!function(window){
	if (!Array.prototype.indexOf){
		  Array.prototype.indexOf = function(elt /*, from*/){
		    var len = this.length >>> 0;

		    var from = Number(arguments[1]) || 0;
		    from = (from < 0)
		         ? Math.ceil(from)
		         : Math.floor(from);
		    if (from < 0)
		      from += len;

		    for (; from < len; from++){
		      if (from in this && this[from] === elt)
		        return from;
		    }
		    return -1;
		  };
		}
	var HTMLTurbo=function(selector){
	}
	HTMLTurbo.util={};
	HTMLTurbo.module={};
	HTMLTurbo.page={};
	HTMLTurbo.control={}
	
	HTMLTurbo.prototype.context=".ht ";
	HTMLTurbo.prototype.controlList=new Array();
	HTMLTurbo.prototype.maxControlId=10000;
	HTMLTurbo.prototype.frameWindowArray=new Array();
	HTMLTurbo.prototype.focusFrameWindow=null;
	HTMLTurbo.prototype.inited=false;
	HTMLTurbo.prototype.console=null;

    HTMLTurbo.prototype.autoDialog=false;
    HTMLTurbo.prototype.autoFrameWindow=false;

	HTMLTurbo.prototype.init=function(){
		if(this.inited==false){
			this.inited=true;
			this.update(".ht");
		}
		//this.console=new Console();
	}
	HTMLTurbo.prototype.update=function(context){
		if(typeof context!="undefined"){
			this.context=context;
		}else{
			this.context=".ht "
		}
		//console.log(context);
		this.updateConsole();
		this.updateA();
		this.updateInput();
		this.updateSelect();
		this.updateIframe();
		this.updateTable();
		
		this.updateMasker();
		this.updateLoading();
		
		this.updateBridge();
		

		this.updateAutoFrameWindow();
		
		this.updateControls(this.context);

        this.updateAutoDialog();
		ht.loading.close()
	}
	HTMLTurbo.prototype.updateConsole=function(){
		if(typeof(console)=="undefined"){
			window.console=function(){}
			window.console.log=function(object){}
		};
		this.console=new Console();
	}
	HTMLTurbo.prototype.updateControls=function(context){
		var selectors=$("[data-ht-control]",context)
		for(var i=0;i<selectors.length;i++){
			this.createControl(selectors.eq(i))
		}
	}
	HTMLTurbo.prototype.createControl=function(selector,className){
		if(typeof className=="undefined"){
			var className=$(selector).attr("data-ht-control");
		}
		var options=$(selector).attr("data-ht-options");
		//console.log(className);
		var evalStr="new HTMLTurbo.control."+className+"(selector,options)";
		var control=eval(evalStr);
		control.init();
		this.appendControl(control);
		return control;
	}
	HTMLTurbo.prototype.appendControl=function(control){
		this.maxControlId++;
		var htid="ht"+this.maxControlId;
		control.setId(htid);
		this.controlList.push(control);
	}
	HTMLTurbo.prototype.getControl=function(selector){
		var htid=$(selector).eq(0).attr("data-ht-id");
		var control=null;
		console.log(this.controlList);
		for(var i=0;i<this.controlList.length;i++){
			if(this.controlList[i].id==htid){
				control=this.controlList[i]
				break;
			}
		}
		return null;
	}
	
	HTMLTurbo.prototype.getTabs=function(selector){
		var className="Tabs";
		var control=this.getControl(selector);
		if(control==null){
			control=this.createControl(selector,className);
		}
		return control
	}
	
	//A
	HTMLTurbo.prototype.updateA=function(){
		var total
		var i=0;
		var selectors=$("a",this.context)
		var a=null;
		total=selectors.length;
		for(i=0;i<total;i++){
			this.createControl(selectors.eq(i),"A");
		}
	}
	//Input
	HTMLTurbo.prototype.updateInput=function(){
		var selectors=$("input",this.context);
		var total=selectors.length;
		
		var selector=null;
		var type=''
		var list="";
		var input=null;
		for(var i=0;i<total;i++){
			selector=selectors.eq(i);
			type=selector.attr("type");
			list=selector.attr("list");
			if(type=="int"){
				this.createControl(selector,"IntInput");
				continue;
			}
			if(type=="number"){
				this.createControl(selector,"NumberInput");
				continue;
			}
			if(type=="date"){
				this.createControl(selector,"DateInput");
				continue;
			}
			if(type=="time"){
				this.createControl(selector,"TimeInput");
				continue;
			}
			if(type=="text"){
				this.createControl(selector,"TextInput");
				continue;
			}
		}
	}
	//Select
	HTMLTurbo.prototype.updateSelect=function(){
		var selectors=$("select",this.context)
		var total=selectors.length;
		for(var i=0;i<total;i++){
			var selector=selectors.eq(i);
			this.createControl(selector,"Select");
		}
	}
	//IFrame
	HTMLTurbo.prototype.updateIframe=function(){
		var selectors=$("iframe",this.context)
		var total=selectors.length;
		for(var i=0;i<total;i++){
			var selector=selectors.eq(i);
			this.createControl(selector,"Iframe");
		}
	}
	//IFrame
	HTMLTurbo.prototype.updateTable=function(){
		var selectors=$("table",this.context)
		var total=selectors.length;
		for(var i=0;i<total;i++){
			var selector=selectors.eq(i);
			this.createControl(selector,"Table");
		}
	}
	//Masker
	HTMLTurbo.prototype.updateMasker=function(){
		var selector=".ht-Masker";
		var masker=this.createControl(selector,"Masker");
		this.masker=masker;
	}
	
	//Loading
	HTMLTurbo.prototype.updateLoading=function(){
		var selector=".ht-Loading";
		var loading=this.createControl(selector,"Loading");
			loading.setMasker(this.masker);
		this.loading=loading;
	}
	
	//Bridge
	HTMLTurbo.prototype.updateBridge=function(){
		this.createControl(undefined,"Bridge");
	}
	
	
	
	//Dialog
	HTMLTurbo.prototype.updateAutoDialog=function(){
		var selectors=$(".ht-Dialog.auto",this.context)
		var self=this;
		if(selectors.length>0){
		    this.autoDialog=true;
        }
		selectors.each(function(index, selector) {
			self.createControl(selector,"Dialog");
	    });
	}
	
	HTMLTurbo.prototype.openDialog=function(selector){
		//var dialog=new HTMLTurbo.control.Dialog(selector);
		this.createControl(selector,"Dialog");
	}
	//frameWindow
	HTMLTurbo.prototype.updateAutoFrameWindow=function(){
		var self=this;
		var selectors=$(".ht-Popup.frame.auto",this.context)
		selectors.each(function(index, selector) {
	       	var href=$(selector).attr("href");
		    var frameWindow=self.openFrameWindow(href,"","");
			self.setFocusFrameWindow(frameWindow);
	    });
	}
	HTMLTurbo.prototype.openFrameWindow=function(url,title,size){
		console.log(url);
		//var frameWindow=new HTMLTurbo.control.FrameWindow();
		var frameWindow=this.createControl(undefined,"FrameWindow");
		frameWindow.open(url,title,size);
		this.frameWindowArray.push(frameWindow);
		
		this.setFocusFrameWindow(frameWindow);
		return frameWindow;
	}
	HTMLTurbo.prototype.setFocusFrameWindow=function(focusFrameWindow){
		this.focusFrameWindow=focusFrameWindow;
	}
	HTMLTurbo.prototype.hideAllFrameWindow=function(){
		var frameWindowArray=this.frameWindowArray
		var total=frameWindowArray.length;
		for(var i=0;i<total;i++){
			frameWindowArray[i].hide();
		}
		return false;
	}
	HTMLTurbo.prototype.closeAllFrameWindow=function(){
		var frameWindowArray=this.frameWindowArray
		var total=frameWindowArray.length;
		for(var i=0;i<total;i++){
			frameWindowArray[i].close();
		}
		return false;
	}
	HTMLTurbo.prototype.closeFocusFrameWindow=function(){
		this.focusFrameWindow.close();
	}
		// Builder
	var Builder=function(selector,options){
	}
	Builder.prototype.init=function(){
	}
	Builder.prototype.update=function(context){
	}
	HTMLTurbo.util.Builder=Builder;
	// PatternBuilder 规则
	var PatternBuilder=function(){}
	PatternBuilder.text=function(min,max){
		var str="^[\\s\\S]{"+min+","+max+"}$";
		return str;
	}
	PatternBuilder.content=function(min,max){
		var str="^[\\s\\S]{"+min+","+max+"}$";
		return str;
	}
	PatternBuilder.letterNumber=function(min,max){
		var str="^[a-zA-Z0-9]{"+min+","+max+"}$";
		return str;
	}
	PatternBuilder.letter=function(min,max){
		var str="^[a-zA-Z]{"+min+","+max+"}$";
		return str;
	}
	PatternBuilder.int=function(min,max){
		var str="^[0-9]{"+min+","+max+"}$";
		return str;
	}
	PatternBuilder.float=function(integer,float){
		var str="^((([1-"+integer+"]\\d*)|0)(\\.\\d{1,"+float+"})?)$";
		return str;
	}
	PatternBuilder.number=function(integer,float){
		var str="^((([1-"+integer+"]\\d*)|0)(\\.\\d{1,"+float+"})?)$";
		return str;
	}
	PatternBuilder.email=function(){
		var str="^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
		return str;
	}
	PatternBuilder.tel=function(){
		var str="^.{1,20}$";
		return str;
	}
	PatternBuilder.mobile=function(){
		var str="^[0-9]{11,11}$";
		return str;
	}
	PatternBuilder.unequal=function(str){
		//^(?!0$)
		var str="^(?!"+str+"$)";
		return str;
	}
	
	HTMLTurbo.util.PatternBuilder=PatternBuilder;
	// Validator 验证器
	var Validator=function(){
	}
	Validator.prototype.init=function(){
	}
	HTMLTurbo.control.Validator=Validator;
	// BrowserController 浏览器控制器
	var BrowserController=function(){}
	//后退强制前进
	BrowserController.forwardLast=function(){
		window.history.forward(1);
	}
	//屏蔽右键
	BrowserController.disabledContextMenu=function(){
		document.oncontextmenu = function (e) {
			return false;
		}
	}
	//屏蔽F5
	BrowserController.disabledF5=function(){
		document.onkeydown = function (e) {
			e = window.event || e;
			var keycode = e.keyCode || e.which;
			if (e.ctrlKey || e.altKey || e.shiftKey || keycode >= 112 && keycode <= 123) {
				if (window.event) { // ie
					try {
						e.keyCode = 0;
					} catch (e) {
						console.log(e);
					}
					e.returnValue = false;
				} else { // ff
					e.preventDefault();
				}
				return false;
			}
		}
	}
	//禁止复制
	BrowserController.disableCopy=function(context){
	}
	//禁止复制
	BrowserController.enableCopy=function(context){
	}
	
	//处理键盘事件 禁止后退键（Backspace）密码或单行、多行文本框除外 
	BrowserController.disabledBackspace=function(){
		//禁止后退键 作用于Firefox、Opera 
		$(document).bind("keypress",function(event){return banBackSpace(event);})
		//window.document.onkeypress = banBackSpace;
		
		//禁止后退键 作用于IE、Chrome 
		$(document).bind("keydown",function(event){return banBackSpace(event);})
		//window.document.onkeydown = banBackSpace;
		
		//处理键盘事件 禁止后退键（Backspace）密码或单行、多行文本框除外 
		function banBackSpace(e) {
			var ev = e || window.event; //获取event对象 
			var obj = ev.target || ev.srcElement; //获取事件源 
			var t = obj.type || obj.getAttribute('type'); //获取事件源类型 
			//获取作为判断条件的事件类型 
			var vReadOnly = obj.getAttribute('readonly');
			var vEnabled = obj.getAttribute('enabled');
			//处理null值情况 
			vReadOnly = (vReadOnly == null) ? false : vReadOnly;
			vEnabled = (vEnabled == null) ? true : vEnabled;
			//当敲Backspace键时，事件源类型为密码或单行、多行文本的， 
			//并且readonly属性为true或enabled属性为false的，则退格键失效 
			var flag1 = (ev.keyCode == 8 && (t == "password" || t == "text" || t == "textarea") && (vReadOnly == true || vEnabled != true)) ? true : false;
			//当敲Backspace键时，事件源类型非密码或单行、多行文本的，则退格键失效 
			var flag2 = (ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea") ? true : false;
			//判断 
			if (flag2) {
				return false;
			}
			if (flag1) {
				return false;
			}
		}
	}
	//获得cookie
	BrowserController.getCookie=function(name)
	{
		var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
		if(arr=document.cookie.match(reg)){
			return unescape(arr[2]);
		}else{
			return null;
		}
	}
	BrowserController.setCookie=function(name,value)
	{
		document.cookie=name+"="+value;
	}
	BrowserController.unSelectableDisabled=function(){
		$("*:disabled").attr('unselectable','on');
	}
	
	BrowserController.getBrowserName=function(){
		var browserName="";
		var agent = navigator.userAgent.toLowerCase();
		console.log(agent);
		
		var regExp=new RegExp("rv:11");
		if(regExp.test(agent)){
			browserName="ie";
			return browserName;
		}
		var regExp=new RegExp("msie");
		if(regExp.test(agent)){
			browserName="ie";
			return browserName;
		}
		
		var regExp=new RegExp("firefox");
		if(regExp.test(agent)){
			browserName="firefox";
			return browserName;
		}
		var regExp=new RegExp("chrome");
		if(regExp.test(agent)){
			browserName="chrome";
			return browserName;
		}
		return "未知";
	}
	BrowserController.getBrowserVersion=function(){
		var version="暂未开发";
		return version;
	}
	
	BrowserController.disableVersion=function(){
		var version="暂未开发";
		return version;
	}
	HTMLTurbo.util.BrowserController=BrowserController;
	// DateUtils 日期工具
	var DateUtils=function(){}
	DateUtils.getYesterday=function(){
		var tomorrowDate=new Date();
	    tomorrowDate.setDate(tomorrowDate.getDate()-1);
	    return tomorrowDate
	}
	DateUtils.getToday=function(){
		var today=new Date();
		return today;
	}
	DateUtils.getStepDate=function(date,step){
		var stepDate=new Date()
		stepDate.setDate(date.getDate()+step);
	    return stepDate; 
	}
	DateUtils.getTomorrowDay=function(date){
		if(typeof date=="undefined"){
			var date=new Date(); 
		}
		var tomorrowDay=new Date(); 
	    tomorrowDay.setDate(date.getDate()+1);
	    return tomorrowDay; 
	}
	DateUtils.getAfterTomorrowDay=function(date){
		if(typeof date=="undefined"){
			var date=new Date(); 
		}
		var afterTomorrowDay=new Date();     
	    afterTomorrowDay.setDate(date.getDate()+2);
	    return afterTomorrowDay;
	}
	DateUtils.getWeekFirstDay=function(date){
		if(typeof date=="undefined"){
			var date=new Date(); 
		}
	    var weekFirstDay=new Date(date-(date.getDay()-1)*86400000);
	    return weekFirstDay;
	}
	DateUtils.getWeekLastDay=function(date){
		if(typeof date=="undefined"){
			var date=new Date(); 
		}
	    var weekFirstDay=new Date(date-(date.getDay()-1)*86400000);
	    var weekLastDay=new Date((weekFirstDay/1000+6*86400)*1000);
		return weekLastDay;   
	}
	
	DateUtils.getMonthFirstDay=function(date){     
		if(typeof date=="undefined"){
			var date=new Date(); 
		}    
	    var monthFirstDay=new Date(date.getFullYear(),date.getMonth(),1);     
	    return monthFirstDay;
	}
	
	DateUtils.getMonthLastDay=function(date){     
		if(typeof date=="undefined"){
			var date=new Date(); 
		}
	    var monthFirstDay=new Date(date.getFullYear(),date.getMonth()+1,1);     
	    var monthLastDay=new Date(monthFirstDay-86400000);     
		return monthLastDay;
	}
	DateUtils.formatToDateStr=function(date){
		var year=date.getFullYear();
		var month=Number(date.getMonth())+1
		var day=date.getDate();
		if(month<10){
			month="0"+month;
		}
		if(day<10){
			day="0"+day;
		}
		return year+"-"+month+"-"+day;
	}
	HTMLTurbo.util.DateUtils=DateUtils;

	// Container 规则解析器
	// 对于同名字段的例如checkbox暂无法解决，暂时解决办法checkbox不同名来解决
	var PatternBuilder=HTMLTurbo.util.PatternBuilder;
	
	var RuleParser=function(selector){
		this.selector=selector;
		this.init()
	}
	RuleParser.prototype.rule=null;
	RuleParser.prototype.classNameRule=null;
	RuleParser.prototype.submitRule=null;
	
	RuleParser.prototype.defaultClassName="";
	
	RuleParser.prototype.init=function(){
		var defaultClassName=$(this.selector).attr("class");
		if(typeof defaultClassName!="undefined"){
			this.defaultClassName=defaultClassName;
		}
	}
	RuleParser.prototype.loadRule=function(url){
		var self=this;
		var options={
			url: url,
			dataType:"json",
			cache:false,
			success: function(data, textStatus, jqXHR){
				self.loadRuleSuccess(data);
			},
			error :function(){
				alert("rule load error ");
			}
		}
		$.ajax(options);
	}
	RuleParser.prototype.loadRuleSuccess=function(data){
		this.setRule(data);
	}
	RuleParser.prototype.setRule=function(rule){
		this.rule=rule;
		this.setClassNameRule(rule.classNameRule);
		this.setSubmitRule(rule.submitRule);
	}
	RuleParser.prototype.bindChange=function(type){
		var self=this;
		var listenFields=this.classNameRule.listenFields;
		for(var i=0;i<listenFields.length;i++){
			var name=listenFields[i];
			$("[name='"+name+"']",this.selector).bind("change",function(event){
				if(type=="className"){
					self.updateClassNameRule();
				}
				if(type=="submit"){
					self.updateSubmitRule();
				}
			})
		}
	}
	RuleParser.prototype.getRuleNameList=function(matchRules,dataList){
		var ruleNames="";
		var ruleNameList=new Array();
		
		var data=new Array();
		var name="";
		var value="";
		
		var matchRule=null;
		
		var evalStr="";
		//console.log(dataList);
		
		for(var i=0;i<dataList.length;i++){
			data=dataList[i];
			name=data.name;
			value=data.value;
			value=value.replace(/\r\n|\r|\n/g,"\\n");
			name=name.replace("[]","");
			evalStr="var "+name+"='"+value+"'";
			//console.log(evalStr);
			eval(evalStr);
		}
		for(var i=0;i<matchRules.length;i++){
			matchRule=matchRules[i]
			evalStr=matchRule.matchStr
			
			//值为空时try
			try{
				if(eval(evalStr)){
					ruleNameList.push(matchRule.name);
				}
			}catch(e){
				//console.log(e)
			}
		}
		return ruleNameList;
	}
	
	
	
	
	
	
	
	
	
	
	/*---className block---*/
	RuleParser.prototype.setClassNameRule=function(classNameRule){
		this.classNameRule=classNameRule
		this.bindChange("className");
		this.updateClassNameRule();
	}
	
	RuleParser.prototype.updateClassNameRule=function(){
		var dataList=this.getDataList();
		var ruleNameList=this.getRuleNameList(this.classNameRule.matchRules,dataList);
		var ruleNames=ruleNameList.join(" ");
		var className="";
		if(this.defaultClassName!=""){
			className=this.defaultClassName+" ";
		}
		className+=ruleNames;
		console.log("className="+className);
		$(this.selector).attr("class",className);
	}
	
	
	/*---submit block---*/
	RuleParser.prototype.setSubmitRule=function(submitRule){
		this.submitRule=submitRule
		this.bindChange("submit");
		this.updateSubmitRule();
	}
	RuleParser.prototype.updateSubmitRule=function(){
		var dataList=this.getDataList();
		var ruleNameList=this.getRuleNameList(this.submitRule.matchRules,dataList);
		var ruleNames=ruleNameList.join(" ");

		console.log("submitRuleNames="+ruleNames);
		
		this.updateSubmitRuleRuleFieldList(ruleNameList);
	}
	
	
	RuleParser.prototype.extend=function(obj1,obj2){
		//console.log(obj1);
		//console.log(obj2);
		for(var i in obj2){
			//不做继承参数判断只继承
			//obj1[i]=obj2[i];
			
			//继承参数做判断
			for(var j in obj1){
				if(obj1[j].name==obj2[i].name){
					obj1[j]=this.extendPara(obj1[j],obj2[i]);
					break;
					//obj1[j]=obj2[i];
					//break;
				}
			}
		}
		return obj1;
	}
	RuleParser.prototype.extendPara=function(obj1,obj2){
		var key="";
		var value="";
		var evalStr="";
		for(var i in obj2){
			key=i;
			evalStr="obj2."+key
			value=eval(evalStr);
			evalStr="obj1."+key+"=value"
			eval(evalStr)
		}
		return obj1;
	}
	RuleParser.prototype.updateSubmitRuleRuleFieldList=function(ruleNameList){
		var ruleGroups=this.submitRule.ruleGroups;
		var ruleGroup=null;
		var ruleGroupList=new Array();
		//console.log(ruleNameList);
		//var resultGroup={};
		
		//规则组列表
		for(j in ruleNameList){
			var ruleName=ruleNameList[j];
			for(i in ruleGroups){
				if(ruleGroups[i].name==ruleName){
					ruleGroup=ruleGroups[i];
					//console.log(ruleGroup);
					ruleGroup=$.extend(true,{},ruleGroup)
					ruleGroupList.push(ruleGroup);
				}
			}
		}
		//console.log(ruleGroupList);
		//字段规则列表
		var fieldRuleList=ruleGroupList[0].fieldRuleList;
		//console.log(fieldRuleList);
		//fieldRuleList=$.extend({},fieldRuleList)
		for(var i=1;i<ruleGroupList.length;i++){
			fieldRuleList=this.extend(fieldRuleList,ruleGroupList[i].fieldRuleList)
		}
		if(fieldRuleList==null){
			return ;
		}
		//var ruleList=this.ruleData.submitRules.base;
		//this.submitRuleList=ruleList;
		//var element=null;
		
		//console.log(fieldRuleList);
		var rule=null;
		for(var i=0;i<fieldRuleList.length;i++){
			fieldRule=fieldRuleList[i];
			this.updateFieldRule(fieldRule);
		}
		this.submitFieldRuleList=fieldRuleList;
	}
	RuleParser.prototype.submitFieldRuleList=null;
	
	RuleParser.prototype.updateFieldRule=function(rule){
		var label=rule.label;
		var name=rule.name;
		var required=rule.required;
		var pattern=rule.pattern;
		var patternName=rule.patternName;
		var placeholder=rule.placeholder;
		var title=rule.title;
		var type=rule.type;
		var tips=rule.tips;
		//console.log(name);
		
		var elements=$("[name=\""+name+"\"]",this.selector);
		
		//生成规则
		if(patternName!=""){
			var evalStr="PatternBuilder."+patternName;
			if(pattern==""){
				pattern=eval(evalStr);
			}
		}
		var isVisible=$(elements).is(":visible")
		//附加规则
		if(pattern!=""){
			if(type!="select"){
				if(isVisible){
					elements.prop("pattern",pattern);
				}
			}
		}else{
			elements.removeAttr("pattern");
		}
		//增加必填
		if(required){
			if(isVisible){
				elements.prop("required","required");
				//console.log(name+" 1");
			}
		}else{
			//console.log(name+" 2");
			elements.removeProp("required");
		}
		
		//增加提示
		if(title){
			elements.attr("title",title);
		}
		//增加提示
		if(placeholder){
			elements.attr("placeholder",placeholder);
		}
		//增加字段名称
		var labelElement=this.getLabelElement(elements);
		if(labelElement){
			var labelHtml="";
			if(required){
				labelHtml+="<span class=\"required\">*</span>";
			}
			labelHtml+=label+"：";
			labelElement.html(labelHtml);
		}
		
		//增加提示
		if(tips!=""){
			var tipsElement=this.getTipsElement(elements);
			if(tipsElement){
				var tipsHtml="";
				tipsHtml=tips;
				tipsElement.html(tipsHtml);
			}
		}
	}
	RuleParser.prototype.getLabelElement=function(elements){
		var labelElement=elements.parent().find("label");
		//console.log(labelElement);
		if(!labelElement){
			//console.log(11);
			labelElement=this.getLabelElement(elements.parent());
		}
		return labelElement;
	}
	RuleParser.prototype.getTipsElement=function(elements){
		var tipsElement=elements.parent().find(".tips");
		if(tipsElement.length==0){
			tipsElement=$("<span class=\"tips\"></span>");
			elements.parent().append(tipsElement);
		}
		return tipsElement;
	}
	
	RuleParser.prototype.getDataList=function(){
		var serializeArray=$(this.selector).serializeArray();
		return serializeArray;
	}
	RuleParser.prototype.validate=function(){
		var dataList=this.getDataList();
		
		var ruleList=this.submitFieldRuleList;
		var rule=null;
		var value=null;
		var target=null;
		
		var name,label,type,required,pattern,patternName,placeholder,title,tips,maxLength;

		
		var result=null;
		var resultList=new Array();
		//console.log(ruleList);
		for(var i=0;i<ruleList.length;i++){
			rule=ruleList[i];
			//console.log(rule);
			
			name=rule.name;
			type=rule.type;
			required=rule.required;
			label=rule.label;
			pattern=rule.pattern;
			patternName=rule.patternName;
			title=rule.title;
			value=this.getValueByName(dataList,name);
			if(typeof value=="undefined"){
				value="";
			}
			//console.log(value);
			target=$("[name="+name+"]",this.element);
			
			result=new Result();
			result.target=name;
			result.tips="";
			result.event=Result.EVENT_SUCCESS;
			
			//跳过源始密码的验证
			if(name=="sourcePassword"){
				continue;
			}
			//事件提示语
			var eventTips="";
			if(required){
				if(type=="select"){
					eventTips=label+" 必选 "+title;
				}else{
					eventTips=label+" 必填 "+title;
				}
			}else{
				eventTips=label+" "+title;
			}
			//必填验证
			if(required){
				if(value==""){
					//console.log(name);
					result.target=name
					result.tips=eventTips
					result.event=Result.EVENT_FAIL;
					resultList.push(result);
					continue;
				}
			}
			//规则验证
			if(patternName!=""){
				var evalStr="PatternBuilder."+patternName;
				if(pattern==""){
					pattern=eval(evalStr);
				}
			}
			if(value!=""){
				if(pattern!=""){
					//if(type!="select"){
						var regExp=new RegExp(pattern);
						//console.log(value);
						//console.log(pattern);
						if(!regExp.test(value)){
							result.target=name
							result.tips=eventTips
							result.event=Result.EVENT_FAIL;
							resultList.push(result);
							continue;
						};
					//}
				}
			}
			//console.log(i);
			resultList.push(result);
		}
		//console.log(resultList);
		
		//最后结果
		result=new Result();
		result.event=Result.EVENT_SUCCESS
		result.resultList=resultList;
		this.validateResult=result;
		
		for(var i=0;i<resultList.length;i++){
			if(resultList[i].event==Result.EVENT_FAIL){
				result.event=Result.EVENT_FAIL
				break;
			}
		}
		if(result.event==Result.EVENT_SUCCESS){
			return true;	
		}else{
			return false;
		}
	}
	RuleParser.prototype.getValueByName=function(dataList,name){
		var value;
		var data;
		for(var i=0;i<dataList.length;i++){
			data=dataList[i]
			if(data.name==name){
				value=data.value;
			}
		}
		return value;
	}
	
	
	
	var Result=function(){}
	Result.EVENT_SUCCESS="eventSuccess";
	Result.EVENT_FAIL="eventFail";
	Result.prototype.target=""
	Result.prototype.action=""
	Result.prototype.event=""
	Result.prototype.tips=""
	Result.prototype.resultList=null
	Result.prototype.getResultListFailTips=function(){
		var resultList=this.resultList;
		var tips="";
		for(var i=0;i<resultList.length;i++){
			if(resultList[i].event==Result.EVENT_FAIL){
				tips+=resultList[i].tips+"\n";
			}
		}
		return tips;
	}
	HTMLTurbo.util.RuleParser=RuleParser;
	// Control 控件基类
	var Control = function() {
	}
	Control.prototype.id="";
	Control.prototype.htId="";
	
	Control.prototype.element = null;
	Control.prototype.selector = null;
	
	Control.prototype.init = function() {
	}
	Control.prototype.setId = function(id) {
		this.id=id;
		$(this.element).attr("data-ht-id",id);
	}
	Control.prototype.getId = function() {
		return this.id;
	}
	Control.prototype.setElement = function(element) {
		$(element).removeAttr("data-ht-control");
		this.element=element;
	}
	Control.prototype.getElement = function() {
		return this.element;
	}
	
	Control.prototype.setSelector = function(selector) {
		this.selector=selector;
	}
	Control.prototype.getSelector = function() {
		return this.selector;
	}
	Control.prototype.create = function() {
	}
	Control.prototype.update = function() {
	}
	Control.prototype.reset = function() {
	}
	Control.prototype.open = function() {
	}
	Control.prototype.close = function() {
	}
	Control.prototype.focusOpen = function() {
	}
	Control.prototype.focusClose = function() {
	}
	HTMLTurbo.control.Control=Control;
	// A 标签
	var A=function(selector){
		this.selector=selector;
		this.element=$(selector).get(0);
	}
	A.prototype=new Control();
	A.prototype.init=function(){
		this.update();
	}
	A.prototype.update=function(){
		var self=this;
		if($(this.element).attr("href")=="" || this.element.getAttribute("href")=="" || this.element.getAttribute("href")==null){
			this.element.removeAttribute("href")
		}
		
		/*if(this.element.getAttribute("href")=="" || this.element.getAttribute("href")=="#" || "" || typeof(this.element.getAttribute("href"))=="object"){
			this.element.removeAttribute("href")
			this.element.removeAttribute("target")
		}*/
		$(this.element).bind("click",function(event){return self.clickHandle(event)})
		
		/*if(this.element.target=="autoWindowFrame"){
			var src=$(this.element).attr("href")
			var title=this.element.getAttribute("title")
			if(src!="" && typeof(src)!="undefined"){
				top.windowFrameOpen(src,title);
			}
		}*/
	}
	
	
	A.prototype.clickHandle=function(event){
		//点击完后变到已查看 viewed状态
		if(this.element.getAttribute("class")!="" && this.element.getAttribute("class")!=null){
			if(this.element.getAttribute("class").indexOf("clickToViewed")!="-1"){
				//alert("clickToViewed");
				this.element.className+=" viewed";
				if(this.element.innerHTML=="查看"){
					this.element.innerHTML="已查看"
				}
				/*try{
					var parentNode=this.element.parentNode.parentNode;
					var aElements=$("a.clickToViewed",parentNode)
					for(var i=0;i<aElements.length;i++){
						aElements.eq(i).removeClass("clickToViewed")
						aElements.eq(i).addClass("viewed")
					}
				}catch(errors){
					console.log(errors);
				}*/
			}
		}
		var href=this.element.getAttribute("href")
		var title=this.element.getAttribute("title")
		var className=this.element.getAttribute("class")

		//弹出匹配
		var regExp=new RegExp("ht-Popup");console.log(className);
		if(regExp.test(className)){
			return this.popupHandle();
		}
		//target方式弹出
		if(this.element.target=="ht-newFrameWindow"){
			if(href!="" && href!="#" && typeof(href)!="undefined" && href!=null){
				href=this.element.href
				var frameWindow=top.htmlTurbo.openFrameWindow(href,title,"");
				top.htmlTurbo.setFocusFrameWindow(frameWindow)
			}
			return false;
		}
		if(this.element.target=="ht-newLargeFrameWindow"){
			if(href!="" && href!="#" && typeof(href)!="undefined" && href!=null){
				href=this.element.href
				var frameWindow=top.htmlTurbo.openFrameWindow(href,title,"large");
				top.htmlTurbo.setFocusFrameWindow(frameWindow)
			}
			return false;
		}
		if(this.element.target=="ht-newSmallFrameWindow"){
			if(href!="" && href!="#" && typeof(href)!="undefined" && href!=null){
				href=this.element.href
				var frameWindow=top.htmlTurbo.openFrameWindow(href,title,"small");
				top.htmlTurbo.setFocusFrameWindow(frameWindow)
			}
			return false;
		}
		
		
		if(this.element.target=="ht-newFullScreenWindowFrame"){
			if(href!="" && href!="#" && typeof(href)!="undefined" && href!=null){
				href=this.element.href
				var frameWindow=top.htmlTurbo.openFrameWindow(href,title,"fullScreen");
				top.htmlTurbo.setFocusFrameWindow(frameWindow)
			}
			return false;
		}
		if(this.element.target=="ht-newFreeWindowFrame"){
			if(href!="" && href!="#" && typeof(href)!="undefined" && href!=null){
				href=this.element.href
				var frameWindow=top.htmlTurbo.openFrameWindow(href,title,"free");
				top.htmlTurbo.setFocusFrameWindow(frameWindow)
			}
			return false;
		}
		
		if(this.element.getAttribute("target")=="_blank"){
			if(href=="" || href=="#"){
				return false;
			}
		}
		/*
		if(this.element.target=="windowFrame"){
			var href=this.element.href
			var title=this.element.title
			//console.log(window)
			//alert(href.indexOf("##"))
			if(href.indexOf("##")==-1 || !href.indexOf("##")){
				window.openedFrameWindow=top.windowFrameOpen(title,href,window);
			}
			return false;
		}
		 */
	}











    // A 标签
    var A=function(selector){
        this.selector=selector;
        this.element=$(selector).get(0);
    }
    A.prototype=new Control();
    A.prototype.init=function(){
        this.update();
    }
    A.prototype.update=function(){
        var self=this;
        if($(this.element).attr("href")=="" || this.element.getAttribute("href")=="" || this.element.getAttribute("href")==null){
            this.element.removeAttribute("href")
        }

        /*if(this.element.getAttribute("href")=="" || this.element.getAttribute("href")=="#" || "" || typeof(this.element.getAttribute("href"))=="object"){
            this.element.removeAttribute("href")
            this.element.removeAttribute("target")
        }*/
        $(this.element).bind("click",function(event){return self.clickHandle(event)})

        /*if(this.element.target=="autoWindowFrame"){
            var src=$(this.element).attr("href")
            var title=this.element.getAttribute("title")
            if(src!="" && typeof(src)!="undefined"){
                top.windowFrameOpen(src,title);
            }
        }*/
    }


    A.prototype.clickHandle=function(event){
        //点击完后变到已查看 viewed状态
        if(this.element.getAttribute("class")!="" && this.element.getAttribute("class")!=null){
            if(this.element.getAttribute("class").indexOf("clickToViewed")!="-1"){
                //alert("clickToViewed");
                this.element.className+=" viewed";
                if(this.element.innerHTML=="查看"){
                    this.element.innerHTML="已查看"
                }
                /*try{
                    var parentNode=this.element.parentNode.parentNode;
                    var aElements=$("a.clickToViewed",parentNode)
                    for(var i=0;i<aElements.length;i++){
                        aElements.eq(i).removeClass("clickToViewed")
                        aElements.eq(i).addClass("viewed")
                    }
                }catch(errors){
                    console.log(errors);
                }*/
            }
        }
        var href=this.element.getAttribute("href")
        var title=this.element.getAttribute("title")
        var className=this.element.getAttribute("class")

        //弹出匹配
        var regExp=new RegExp("ht-Popup");
        if(regExp.test(className)){
            return this.popupHandle();
        }
        //target方式弹出
        if(this.element.target=="ht-newFrameWindow"){
            if(href!="" && href!="#" && typeof(href)!="undefined" && href!=null){
                href=this.element.href
                //var frameWindow=top.htmlTurbo.openFrameWindow(href,title,"");
                //top.htmlTurbo.setFocusFrameWindow(frameWindow)

                var frameWindow=top.htmlTurbo.openFrameWindow(href,title,"");
                htmlTurbo.setFocusFrameWindow(frameWindow)
            }
            return false;
        }
        if(this.element.target=="ht-newLargeFrameWindow"){
            if(href!="" && href!="#" && typeof(href)!="undefined" && href!=null){
                href=this.element.href
                //var frameWindow=top.htmlTurbo.openFrameWindow(href,title,"large");
                //top.htmlTurbo.setFocusFrameWindow(frameWindow)

                var frameWindow=top.htmlTurbo.openFrameWindow(href,title,"large");
                htmlTurbo.setFocusFrameWindow(frameWindow)
            }
            return false;
        }
        if(this.element.target=="ht-newSmallFrameWindow"){
            if(href!="" && href!="#" && typeof(href)!="undefined" && href!=null){
                href=this.element.href
                //var frameWindow=top.htmlTurbo.openFrameWindow(href,title,"small");
                //top.htmlTurbo.setFocusFrameWindow(frameWindow)

                var frameWindow=top.htmlTurbo.openFrameWindow(href,title,"small");
                htmlTurbo.setFocusFrameWindow(frameWindow)
            }
            return false;
        }


        if(this.element.target=="ht-newFullScreenWindowFrame"){
            if(href!="" && href!="#" && typeof(href)!="undefined" && href!=null){
                href=this.element.href
                //var frameWindow=top.htmlTurbo.openFrameWindow(href,title,"fullScreen");
                //top.htmlTurbo.setFocusFrameWindow(frameWindow)

                var frameWindow=top.htmlTurbo.openFrameWindow(href,title,"fullScreen");
                htmlTurbo.setFocusFrameWindow(frameWindow)
            }
            return false;
        }
        if(this.element.target=="ht-newFreeWindowFrame"){
            if(href!="" && href!="#" && typeof(href)!="undefined" && href!=null){
                href=this.element.href
                //var frameWindow=top.htmlTurbo.openFrameWindow(href,title,"free");
                //top.htmlTurbo.setFocusFrameWindow(frameWindow)

                var frameWindow=top.htmlTurbo.openFrameWindow(href,title,"free");
                htmlTurbo.setFocusFrameWindow(frameWindow)
            }
            return false;
        }

        if(this.element.getAttribute("target")=="_blank"){
            if(href=="" || href=="#"){
                return false;
            }
        }
        /*
        if(this.element.target=="windowFrame"){
            var href=this.element.href
            var title=this.element.title
            //console.log(window)
            //alert(href.indexOf("##"))
            if(href.indexOf("##")==-1 || !href.indexOf("##")){
                window.openedFrameWindow=top.windowFrameOpen(title,href,window);
            }
            return false;
        }
         */
    }











    A.prototype.popupHandle=function(){
        var href=this.element.getAttribute("href")
        var title=this.element.getAttribute("title")
        var className=this.element.getAttribute("class")
        if(href=="" || href=="#" || href=="##" || href=="###" || typeof(href)=="undefined" || href ==null){
            return false;
        }
        //href属性不是全地址
        href=this.element.href

        target=this.element.target;

        var context=window
        if(target == "_top"){
            context=top
        }
        if(target == "_parent"){
            context=parent
        }
        //top.htmlTurbo.openDialog(href);
        //return false;

        var regExp=null;
        var size="";
        var popupType="frame";

        regExp=new RegExp("frame|Frame");
        if(regExp.test(className)){
            popupType="frame";
        }
        regExp=new RegExp("dialog|Dialog");
        if(regExp.test(className)){
            popupType="dialog";
        }

        //frameWindow
        if(popupType=="frame"){
            regExp=new RegExp("frame");
            if(regExp.test(className)){
                size="";
            }
            regExp=new RegExp("largeFrame");
            if(regExp.test(className)){
                size="large";
            }
            regExp=new RegExp("smallFrame");
            if(regExp.test(className)){
                size="small";
            }
            regExp=new RegExp("fullScreenFrame");
            if(regExp.test(className)){
                size="fullScreen";
            }

            regExp=new RegExp("freeFrame");
            if(regExp.test(className)){
                size="free";
            }
            //if(href!="" && href!="#" && href!="###" && typeof(href)!="undefined" && href!=null){
            //console.log(href);
            //var frameWindow=top.htmlTurbo.openFrameWindow(href,title,size);
            //top.htmlTurbo.setFocusFrameWindow(frameWindow)
            //console.log(target);
            //console.log(context);
            var frameWindow=context.htmlTurbo.openFrameWindow(href,title,size);
            context.htmlTurbo.setFocusFrameWindow(frameWindow)
            return false;
            //}
        }

        //dialog
        if(popupType=="dialog"){
            regExp=new RegExp("dialog");
            if(regExp.test(className)){
                size="";
            }
            regExp=new RegExp("largeDialog");
            if(regExp.test(className)){
                size="large";
            }
            regExp=new RegExp("smallDialog");
            if(regExp.test(className)){
                size="small";
            }
            regExp=new RegExp("fullDialog");
            if(regExp.test(className)){
                size="fullScreen";
            }

            regExp=new RegExp("freeDialog");
            if(regExp.test(className)){
                size="free";
            }
            if(href!="" && href!="#" && typeof(href)!="undefined" && href!=null){
                //top.htmlTurbo.openDialog(href);
                htmlTurbo.openDialog(href);
                return false;
            }
        }

        return true;
    }
    HTMLTurbo.control.A=A;
	// Table 表格
	var Table=function(selector){
		this.selector=selector;
		this.element=$(selector).get(0);
	}
	Table.prototype=new Control();
	Table.prototype.init=function(){
		
		var check=this.element.getAttribute("data-check")
		if(check=="true"){
			this.check();
		}else{
		}
	}
	Table.prototype.check=function(){
		//console.log("table")
		//return false;
		//$("table").each(function(index, element) {
			var thList=[];
			var oldList=$("thead",this.element).find("th");
			for(var i=0;i<oldList.length;i++){
				thList[i]=oldList.eq(i).attr("class");
			}
			var trList=$("tbody",this.element).find("tr");
			for(var i=0;i<trList.length;i++){
				var tdList=trList.eq(i).children("td");
				if(thList.length!=tdList.length&&thList.length>0){
					console.log("第"+(i+1)+"行tr列中的td数量不一致！标准th是"+thList.length+"个而td实际是"+tdList.length);
				}
				for(var j=0;j<tdList.length;j++){
					if(thList[j]!=tdList.eq(j).attr("class")){
						console.log("第"+(i+1)+"行"+(j+1)+"列中的class与规定的不一致！标准的class是"+thList[j]+"而实际的td的名称是"+tdList.eq(j).attr("class"))
					}
				}
			}
		//});
	}
	HTMLTurbo.control.Table=Table;
	// EditableTable 可编辑表格
	var EditableTable=function(selector){
		this.selector=selector;
	}
	EditableTable.prototype.init=function(){
		//console.log("init");
		var self=this;
		var template=$("tbody tr.template",this.selector)
		template=$(template).clone();
		template.removeClass("template");
		this.template=template
		//console.log(this.selector);
		$("tbody tr.template",this.selector).remove();
		
		$("input",this.selector).bind("change",function(event){
			 self.inputChangeHandler(event)
	    });
		$("input",this.selector).bind("dblclick",function(event){
			 self.inputDblclickHandler(event)
	    });
		$(".button",this.selector).bind("click",function(event){
			 self.buttonClickHandler(event)
	    });
		if($("tbody tr",this.selector).length==0){
			this.addRow();
		}
		this.update();
	}
	EditableTable.prototype.inputChangeHandler=function(event){
		this.update();
	}
	EditableTable.prototype.inputDblclickHandler=function(event){
		
	}
	EditableTable.prototype.buttonClickHandler=function(event){
		
	}
	EditableTable.prototype.keydownHandler=function(event){
		return true;
	}
	EditableTable.prototype.keyupHandler=function(event){
		this.update();
		return true;
	}
	
	EditableTable.prototype.validateInteger=function(event){
		var keyCode=event.keyCode;
		//console.log(keyCode);
		if(keyCode==8 || keyCode ==46){
			return true;
		}
		if(keyCode>=37 && keyCode<=40){
			return true;
		}
		var key=event.key;
		var regExp=new RegExp("[0-9]");
		if(regExp.test(key)){
			return true;
		}else{
			return false;
		}
	}
	EditableTable.prototype.validateFloat=function(event){
		var keyCode=event.keyCode;
		//console.log(keyCode);
		if(keyCode==8 || keyCode ==46){
			return true;
		}
		if(keyCode>=37 && keyCode<=40){
			return true;
		}
		var key=event.key;
		var regExp=new RegExp("[0-9\.]");
		if(regExp.test(key)){
			return true;
		}else{
			return false;
		}
	}
	EditableTable.prototype.getDataList=function(){
		var dataList=new Array();
		var data={};
		var self=this;
		var evalStr="";
		
		$("tbody tr",this.selector).each(function(index, element) {
			var children=$(element).children();
			var cell=null;
			var name="";
			data={};
			for(var i=0;i<children.length;i++){
				cell=children[i]
				var name=$(cell).attr("name");
				var value=$(cell).text();
				evalStr="data."+name+"=value";
				eval(evalStr);
			}
			dataList.push(data);
		});
		return dataList;
	}
	EditableTable.prototype.getDataListValue=function(){
		var dataListValue="";
		var dataValue="";
		var value="";
		
		var temp="";
		var m=0;
		$("tbody tr",this.selector).each(function(index, element) {
			var children=$(element).children();
			var cell=null;
			var name="";
			dataValue=",{";
			for(var i=0;i<children.length;i++){
				cell=children[i]
				var name=$(cell).attr("name");
				var value=$(cell).text();
				dataValue+="\""+name+"\":\""+value+"\"";
				if(i<children.length-1){
					dataValue+=",";
				}
			}
			dataValue+="}";
			dataListValue+=dataValue;
		});
		if(dataListValue!=""){
			dataListValue=dataListValue.substr(1);
		}
		dataListValue="["+dataListValue+"]";
		return dataListValue;
	}
	EditableTable.prototype.getValueByName=function(context,name){
		//console.log($("[name='"+name+"']",context).eq(0));
		var value=$("[name='"+name+"']",context).eq(0).text();
		return value;
	}
	EditableTable.prototype.addRow=function(){
		var self=this;
		var row=$(this.template).clone();
		$("tbody",this.selector).append(row);
		this.update();
		
		$("input",row).bind("change",function(event){
			 self.inputChangeHandler(event)
	    });
		$("input",row).bind("dblclick",function(event){
			 self.inputDblclickHandler(event)
	    });
		$(".button",row).bind("click",function(event){
			 self.buttonClickHandler(event)
	    });
	}
	EditableTable.prototype.setValue=function(index,selector,value){
		//$("tbody tr",this.selector).eq(index).find(selector).eq(0).text(value)
		$("tbody tr",this.selector).eq(index).find(selector).eq(0).val(value)
		$("tbody tr",this.selector).eq(index).find(selector).eq(0).change();
	}
	EditableTable.prototype.getRowIndexByCell=function(cell){
		var index=$(cell).parent().parent().find("tr").index($(cell).parent());
		return index;
	}
	EditableTable.prototype.getRowIndex=function(object){
		var row=$(object).parent().parent();
		var index=$(row).parent().find("tr").index(row);
		return index;
	}
	/*EditableTable.prototype.cellClickHandler=function(event){
		var target=event.currentTarget;
		var index=this.getRowIndexByCell(target);
		
		var name=$(target).attr("name");
		console.log(name)
		
		//选择联系人
		/*if(name=="name" || name=="code"){
			selectContact(index);
		}*/
	//}
	
	//更新
	EditableTable.prototype.update=function(){
	}
	HTMLTurbo.control.EditableTable=EditableTable;
	// Iframe 框架
	var Iframe=function(selector){
		this.selector=selector;
		this.element=$(selector).get(0);
	}
	Iframe.prototype=new Control();
	Iframe.prototype.init=function(){
		var self=this;
		this.seamless=$(this.element).attr("seamless");
		if(this.element.src.indexOf("%7B")!="-1"){
			return false;
		}
		if(typeof(this.seamless)!="undefined"){
			this.timer=setInterval(function(){self.update()},100);
			return ;
			//兼容点设置地方
			if(!!document.addEventListener){
				//$(this.element).load(function(event){self.loadCompleteHandle(event);});
				$(this.element).bind("load",function(event){self.loadCompleteHandle(event);});
				//console.log("its up ie8")
			}else{
				this.timer=setInterval(function(){self.update()},100);
				//console.log("its not up ie8")
			}
			//2015.11.24
		}
	}
	Iframe.prototype.loadCompleteHandle=function(event){
		this.adaptiveHeight();
	}
	Iframe.prototype.adaptiveHeight=function(){
		var self=this;
		this.bodyElement=$(this.element).contents().find("body").get(0);
		var height=$(this.bodyElement).outerHeight()
		this.element.style.height=height+"px";
		//console.log("进入了我想走进来的道路");
		$(this.bodyElement).bind("DOMNodeInserted",function(event){
			//var height=$(event.currentTarget).outerHeight()
			var height=$(event.currentTarget).get(0).scrollHeight
			self.element.style.height=height+"px";
		})
		$(this.bodyElement).bind("DOMNodeRemoved",function(event){
			//var height=$(event.currentTarget).outerHeight()
			$(event.currentTarget).css("height","auto");
			$(event.currentTarget).parent("html").css("height","auto");
			var height=$(event.currentTarget).height();
			$(self.element).css("height",height+"px");
		})
	}
	Iframe.prototype.update=function(){
		if(this.element.contentWindow.document.body!=null){
			$(this.element).contents().find("body").css("height","auto");
			$(this.element).contents().find("html").css("height","auto");
			scrollHeight=$(this.element).contents().find("body").height();
			//this.element.contentWindow.document.body.scrollHeight
			//console.log(scrollHeight);
			//this.element.style.height=scrollHeight+"px";
			$(this.element).css("height",scrollHeight+"px")
		}
	}
	HTMLTurbo.control.Iframe=Iframe
	var FocusList=function(){
		this.items=new Array();
	};
	FocusList.prototype=new Control();
	FocusList.prototype.focusNum=0;
	FocusList.prototype.setFocusNum=function(focusNum){
		this.focusNum=focusNum
		this.focusControl(focusNum);
	}
	FocusList.prototype.focusControl=function(focusNum){
		this.total=this.items.length;
		for(var i=0;i<this.total;i++){
			this.items[i].focusClose();
		}
		if(this.total>1){
			this.items[focusNum].focusOpen();
		}else{
			this.items[0].focusOpen();
		}
	};
	HTMLTurbo.control.FocusList=FocusList;
	var FocusListItem=function(){}
	FocusListItem.prototype=new Control();
	FocusListItem.prototype.focusOpen=function(){
		this.element.className="focusOpen";
	};
	FocusListItem.prototype.focusClose=function(){
		this.element.className="focusClose";
	};
	HTMLTurbo.control.FocusListItem=FocusListItem;
	// Input 输入
	var Input=function(selector,options){
		this.selector=selector;
		this.element=$(this.selector).get(0);
	}
	Input.prototype=new Control();
	Input.prototype.init=function(){
	}
	HTMLTurbo.control.Input=Input
	// TextInput 文本输入
	var TextInput=function(selector){
		this.selector=selector;
	}
	TextInput.prototype=new Control();
	TextInput.prototype.optionList=null;
	TextInput.prototype.init=function(){
		var list2=$(this.selector).prop("list");
		var name=$(this.selector).attr("name");
		var selects=$("select[name='"+name+"']");
		
		if(typeof list2=="string"){
		}else{
			if(list2!=null){
				$(selects).remove();
				return ;
			}
		}
		var list=$(this.selector).attr("list");
		
		var parent=this.selector.parent()
		var self=this;
		if(typeof list != "undefined"){
			if(selects.length>0){
				$(this.selector).remove();
				$(selects).show();
			}
		}
		//$(this.selector).bind("input",function(event){self.inputHandler(event)})
	}
	TextInput.prototype.inputHandler=function(event){
		var target=event.currentTarget;
		var value=target.value;
		console.log(value);
	}
	HTMLTurbo.control.TextInput=TextInput;
	// NumberInput 数值输入
	var NumberInput=function(selector){
		if(typeof selector=="undefined"){
			return ;
		}
		this.selector=selector;
		this.init();
	}
	NumberInput.prototype=new Control();
	NumberInput.options={
		valueReg:"^((([1-9]\\d*)|0)(\\.\\d{1,2})?)$",
		valueRegNotFitTips:"请输入数值格式",
		
		minValue:null,
		minValueNotFitTips:"不得小于{value}",
		
		maxValue:null,
		maxValueNotFitTips:"不得大于{value}",
		
		minSelector:null,
		minSelectorNotFitTips:"不得小于最小值",
		
		maxSelector:null,
		maxSelectorNotFitTips:"不得大于最大值"
	}
	NumberInput.prototype.init=function(){
		this.element=$(this.selector).get(0);
		$(this.element).prop("type","text");
		
		var self=this;
		$(this.element).bind("change",function(event){
			self.changeHandle(event);
		})
		this.options=this.getOptions();
	}
	NumberInput.prototype.getOptions=function(){
		var optionsStr=this.element.getAttribute("data-options")
		var options=null;
		if(optionsStr==null){
			options={}
		}else{
			options=eval("({"+optionsStr+"})");
		}
		options=$.extend({},NumberInput.options,options);
		return options;
	}
	NumberInput.prototype.changeHandle=function(event){
		var element=event.currentTarget;
		var value=element.value;
		if(!this.checkValue(value)){
			element.value="";
		};
	}
	NumberInput.prototype.checkValue=function(value){
		if(value==""){
			return true;
		}
		value=parseFloat(value)
		var reg="";
		reg=this.options.valueReg;
		
		var regExp=new RegExp(reg);
		if(!regExp.test(value)){
			var tips=this.options.valueRegNotFitTips;
			alert(tips);
			return false;
		}
		//最大元素限制
		if(this.options.maxSelector!=null){
			var maxValue=$(this.options.maxSelector).val();
			if(maxValue!=""){
				if(maxValue<value){
					var tips=this.options.maxSelectorNotFitTips;
					alert(tips);
					return false;
				}
			}
		}
		//最小元素限制
		if(this.options.minSelector!=null){
			var minValue=$(this.options.minSelector).val();
			if(minValue>value){
				var tips=this.options.minSelectorNotFitTips;
				alert(tips);
				return false;
			}
		}
		//最大值限制
		var maxValue=this.options.maxValue;
		if(maxValue!=null){
			if(maxValue<value){
				var tips=this.options.maxValueNotFitTips;
				tips=tips.replace("{value}",maxValue)
				alert(tips);
				return false;
			}
		}
		//最小值限制
		var minValue=this.options.minValue;
		if(minValue!=null){
			if(minValue>=value){
                console.log(minValue,value);
				var tips=this.options.minValueNotFitTips;
				tips=tips.replace("{value}",minValue)
				alert(tips);
				return false;
			}
		}
		return true;
	}
	NumberInput.prototype.reset=function(){
	}
	HTMLTurbo.control.NumberInput=NumberInput;
	// IntInput 整数输入
	var IntInput=function(selector){
		this.selector=selector;
		this.init();
		this.options.valueReg="^[0-9]{1,9}$";
		this.options.valueRegNotFitTips="请输入整数格式";
	}
	IntInput.prototype=new Control();
	IntInput.prototype=new HTMLTurbo.control.NumberInput()
	HTMLTurbo.control.IntInput=IntInput;
	// DateInput 日期输入
	var DateInput=function(selector){
		this.selector=selector;
		//this.init();
	}
	DateInput.prototype=new Control();
	DateInput.options={
		startDate:"1900-1-1",
		startDateNotFitTips:"不得早于预定的起始时间",
		
		endDate:"2099-12-31",
		endDateNotFitTips:"不得晚于预定的结束时间",
		
		startSelector:"",
		startSelectorNotFitTips:"不得早于选择的起始时间",
		
		endSelector:"",
		endSelectorNotFitTips:"不得晚于选择的结束时间"
	}
	DateInput.prototype.init=function(){
		this.element=$(this.selector).get(0);
		$(this.element).prop("type","text");
		
		$(this.element).addClass("ht-dateInput");
		
		var self=this;
		$(this.element).unbind("click");
		$(this.element).bind("click",function(event){
			self.clickHandle(event);
		})
		this.element.setAttribute("readonly","readonly")
		this.element.setAttribute("readOnly","readonly")
		this.options=this.getOptions();
	}
	DateInput.prototype.getOptions=function(){
		var optionsStr=this.element.getAttribute("data-options")
		var options=null;
		if(optionsStr==null){
			options={}
		}else{
			options=eval("({"+optionsStr+"})");
		}
		options=$.extend({},DateInput.options,options);
		return options;
	}
	DateInput.prototype.clickHandle=function(event){
		this.control=this.getControl();
		document.body.appendChild(this.control)
	}
	DateInput.prototype.getControl=function(){
		this.removeControl();
		var frame=$("<iframe frameborder=\"0\" scrolling=\"no\" class=\"ht-dateSelector\" src=\"/mcp/common/HTMLTurbo/0.3.0/module/control/dateInput/dateInput.html\"></iframe>").get(0);
		
		var top=$(this.element).offset().top+$(this.element).height()+5
		var left=$(this.element).offset().left
		
		frame.style.left=left+"px"
		frame.style.top=top+"px"
	
		var self=this;
		var value=this.getValue();
		
		var options={
			value:value,
			startDate:this.options.startDate,
			endDate:this.options.endDate,
			setDate:function(date){
				self.setDate(date)
			},
			setValue:function(value){
				self.setValue(value);
			},
			removeControl:function(){
				self.removeControl();
			}
		}
		
	
		$(frame).bind("load",function(){
			var calendar=frame.contentWindow.createCalendr(options);
			var buttonGroupElement=frame.contentWindow.createButtonGroup(options)
			
			/*
			//console.log("onload");
			//ie7 在页面中附加样式body无效
			frame.contentWindow.document.body.style.margin="0"
			frame.contentWindow.document.body.style.padding="0"
			frame.contentWindow.document.body.style.backgroundColor="#f8f8f8"
			
			frame.contentWindow.document.body.appendChild(calendar.getElement());
			frame.contentWindow.document.body.appendChild(buttonGroupElement);
			frame.focus();
			*/
		})
		var bodyClick=null;
		//$("body").unbind("click");
		$("body").bind("click",bodyClick=function(e){
			if($(e.target).closest(self.element).length==0 && $(e.target).closest(frame).length == 0){
				self.removeControl();
				$("body").unbind("click",bodyClick);
			}
	    });
		var bodyClick=function(){
			
		}
		/*$(frame).bind("mouseout",function(event){
			self.removeControl();
		})*/
		return frame;
	}
	DateInput.prototype.setDate=function(date){
		var value=Utils.getDateStr(date);
		if(this.checkDate(date)){
			this.setValue(value);
		}
	}
	DateInput.prototype.setStartSelector=function(startSelector){
		this.options.startSelector=startSelector
	}
	DateInput.prototype.setEndSelector=function(endSelector){
		this.options.endSelector=endSelector
	}
	
	DateInput.prototype.setStartDate=function(startDate){
		this.options.startDate=startDate
	}
	DateInput.prototype.setEndDate=function(endDate){
		this.options.endDate=endDate
	}
	DateInput.prototype.checkDate=function(date){
		if(this.options.endSelector!=""){
			var endValue=$(this.options.endSelector).val();
			var endDate=Utils.getDateByDateStr(endValue);
			if(endDate<date){
				alert(this.options.endSelectorNotFitTips);
				return false;
			}
		}
		
		if(this.options.startSelector!=""){
			var startValue=$(this.options.startSelector).val();
			var startDate=Utils.getDateByDateStr(startValue);
			if(startDate>date){
				alert(this.options.startSelectorNotFitTips);
				return false;
			}
		}
		
		var endValue=this.options.endDate;
		var endDate=Utils.getDateByDateStr(endValue);
		if(endDate<date){
			alert(this.options.endDateNotFitTips);
			return false;
		}
	
		var startValue=this.options.startDate;
		var startDate=Utils.getDateByDateStr(startValue);
		if(startDate>date){
			alert(this.options.startDateNotFitTips);
			return false;
		}
		return true;
	}
	DateInput.prototype.setValue=function(value){
		this.value=value;
		this.element.value=value
		this.element.focus();
		this.removeControl();
		$(this.element).change();
	}
	DateInput.prototype.getValue=function(){
		var value=this.element.value;
		return value;
	}
	DateInput.prototype.removeControl=function(){
		$(this.control).remove();
	}
	DateInput.prototype.getButtonGroup=function(options){
		var self=this;
		var container=document.createElement("div")
		container.className="buttonGroup"
		
		var todayElement=document.createElement("a");
		todayElement.innerHTML="今天"
		$(todayElement).bind("click",function(event){
			var dateTime=new Date();
			date=new Date(dateTime.getFullYear(),dateTime.getMonth(),dateTime.getDate())
			options.setDate(date);
		});
		
		
		var clearElement=document.createElement("a");
		clearElement.innerHTML="清除"
		$(clearElement).bind("click",function(event){
			options.setValue("");
			options.removeControl();
		});
		
		
		
		var closeElement=document.createElement("a");
		closeElement.innerHTML="关闭"
		$(closeElement).bind("click",function(event){
			options.removeControl();
		});
		
		container.appendChild(todayElement);
		container.appendChild(clearElement);
		container.appendChild(closeElement);
		return container
	}
	
	
	
	var Utils=function(){}
	Utils.getDate=function(year,month,day){
		var date=new Date(year,month,day);
		return date;
	}
	Utils.getDateByDateStr=function(value){
		//console.log(value);
		value=value.replace(/ .*/g,"");
		
		var dateArray=value.split("-");
		
		var year=dateArray[0];
		var month=dateArray[1];
		var day=dateArray[2];
		
		var date=new Date(year,(month-1),day);
		return date;
	}
	
	
	
	
	Utils.getDateStr=function(date){
		var year=date.getFullYear();
		var month=date.getMonth()+1;
		var day=date.getDate();
	
		if(month.toString().length==1){
			month="0"+month
		}
		var day=date.getDate()
		
		if(day.toString().length==1){
			day="0"+day.toString();
		}
		var dateStr=year+"-"+month+"-"+day;
		return dateStr;
	}
	Utils.getYearMonthDayLength=function(year,month){
		var leapYear = ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ? true: false;
		var length;
		switch (parseInt(month)) {
			case 0:
			case 2:
			case 4:
			case 6:
			case 7:
			case 9:
			case 11:
				length = 31;
				break;
			case 3:
			case 5:
			case 8:
			case 10:
				length = 30;
				break;
			case 1:
				length = leapYear ? 29: 28;
		}
		return length;
	}
	HTMLTurbo.control.DateInput=DateInput;
	// TimeInput 时间输入
	var TimeInput=function(selector,options){
		this.selector=selector;
		//this.init();
	}
	TimeInput.prototype=new Control();
	TimeInput.prototype.init=function(){
		//$(this.selector).prop("type","hidden");
		$(this.selector).hide();
		this.create();
	}
	TimeInput.prototype.create=function(){
		var num="";
		var options="";
		for(var i=0;i<24;i++){
			if(i<10){
				num="0"+i
			}else{
				num=i;
			}
			options+="<option value=\""+num+"\">"+num+"</option>"
		}
		this.hourSelector=$("<select>"+options+"</select>");
		
		var options="";
		for(var i=0;i<60;i++){
			if(i<10){
				num="0"+i
			}else{
				num=i;
			}
			options+="<option value=\""+num+"\">"+num+"</option>"
		}
		this.minuteSelector=$("<select>"+options+"</select>")
		
		$(this.selector).after(this.minuteSelector)
		$(this.selector).after(" : ");
		$(this.selector).after(this.hourSelector)
		
		var self=this;
		$(this.hourSelector).bind("change",function(event){
			self.update();
		})
		$(this.minuteSelector).bind("change",function(event){
			self.update();
		})
	}
	TimeInput.prototype.update=function(){
		var hour=$(this.hourSelector).val();
		var minute=$(this.minuteSelector).val();
		var time=hour+":"+minute+":00";
		console.log(time);
		$(this.selector).val(time);
	}
	
	HTMLTurbo.control.TimeInput=TimeInput;
	// Select 选项
	var Select=function(selector){
		this.selector=selector;
		this.init()
	}
	Select.prototype=new Control();
	Select.prototype.init=function(){
		var options=$(this.selector).get(0).options;
		var selectedOption=$(".selected,.ht-selectedOption",this.selector).eq(0);
		var value=selectedOption.attr("value");
		//只有已选择时则不删除，为SelectGroup所用
		if(options.length>1){
			$(selectedOption).remove();
		}
		var total=options.length;
		for(var i=0;i<total;i++){
			if(value==options[i].value){
				//console.log(i+" "+options[i].value);
				options[i].selected=true;
			}
		}
	}
	HTMLTurbo.control.Select=Select;
	// CheckboxGroup 复选组
	var CheckboxGroup=function(selector){
		this.selector=selector
	}
	CheckboxGroup.prototype=new Control();
	CheckboxGroup.prototype.init=function(){
		var valueElement=$("input[type=hidden]",this.selector).get(0);
		var value=$(valueElement).eq(0).val();
		$(valueElement).remove();
	
		var valueArray=value.split(",");
		var selectors=$("input[type=checkbox]",this.selector);
		
		for(var i=0;i<selectors.length;i++){
			if(valueArray.indexOf(selectors.eq(i).val())>-1){
				selectors.eq(i).attr("checked","checked");
			}
		}
	}
	HTMLTurbo.control.CheckboxGroup=CheckboxGroup;
	// RadioGroup 单选组
	var RadioGroup=function(selector){
		this.selector=selector
	}
	RadioGroup.prototype=new Control();
	RadioGroup.prototype.init=function(){
		var valueElement=$("input[type=hidden]",this.selector).get(0);
		var value=$(valueElement).eq(0).val();
		$(valueElement).remove();
		
		var valueArray=value.split(",");
		var selectors=$("input[type=radio]",this.selector);
		
		for(var i=0;i<selectors.length;i++){
			var value=selectors.eq(i).val();
			if(valueArray.indexOf(value)>-1){
				selectors.eq(i).attr("checked","checked");
			}
		}
	}
	HTMLTurbo.control.RadioGroup=RadioGroup;
	// SelectGroup 选项组
	var SelectGroup=function(selector,options){
		this.selector=selector;
		this.element=$(selector).get(0);
		if(typeof options=="undefined"){
			var dataUrl=$(selector).attr("data-url");
			var options={
				url:dataUrl,
				selectors:[]
			}
			var children=$("select",selector);
			var data=new Object();
			for(var i=0;i<children.length;i++){
				options.selectors.push({selector:children.eq(i),value:children.eq(i).val()})
			}
		}
		this.options=options;
		this.url=options.url;
		this.selectors=options.selectors
		if(typeof(options.optionsFiltration)!="undefined"){
			this.optionsFiltration=options.optionsFiltration;
		}
		
		this.total=this.selectors.length;
	}
	SelectGroup.prototype=new Control();
	SelectGroup.prototype.data=null;
	
	SelectGroup.prototype.init=function(){
		this.selects=new Array();
		this.load(this.options.url)
	}
	SelectGroup.prototype.reset=function(){
		this.loadCompleteHandle(this.data)
	}
	SelectGroup.prototype.optionsFiltration=function(data){
		return data;
	}
	SelectGroup.prototype.load=function(url){
		var self=this;
		url=url;
		var options={
			url: url,
			dataType:"json",
			cache:false,
			success: function(data, textStatus, jqXHR){
				self.loadCompleteHandle(data)
			},
			error :function(){
				//alert("SelectGroup load error ");
			}
		}
		$.ajax(options);
	}
	SelectGroup.prototype.loadCompleteHandle=function(data){
		
		this.data=data;
		this.total=this.options.selectors.length;
		var self=this;
		var select=null;
		var id="";
		var value="";
		var selector="";
		for(var i=0;i<this.total;i++){
			id=this.options.selectors[i].id;
			selector=this.options.selectors[i].selector;
			
			if(typeof selector=="undefined"){
				selector="#"+id
			}
			
			select=new SelectGroup.Select(selector,i,function(num,id){self.selectControl(num,id)})
			select.init();
			this.selects.push(select);
		}
		this.setValues(0,data);
	}
	SelectGroup.prototype.setValues=function(num,data){
		this.selectControl(num,data)
		var value="";
		value=this.options.selectors[num].value;
		if(value!=""){
			this.selects[num].setValue(value);
			if(typeof(data)!="undefined"){
				for(var i=0;i<data.length;i++){
					if(data[i].value==value){
						if(num+1<this.total){
							this.setValues(num+1,data[i].children);
						}
					}
				}
			}
		}
	}
	SelectGroup.prototype.selectControl=function(num,data){
		
		if(this.total<=num){
			return ;
		}
		
		for(var i=0;i<this.total;i++){
			if(i<num){
				this.selects[i].focusOpen();
			}else{
				this.selects[i].focusClose();
			}
		}
		if(typeof(data)!="undefined"){
			var defaultOption=[{
				value:"",
				text:"==请选择=="
			}]
			var childrenData=defaultOption.concat(data);
			childrenData=this.optionsFiltration(childrenData);
			this.selects[num].setData(childrenData);
			this.selects[num].focusOpen();
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	//组合框组.选择框
	SelectGroup.Select=function(selector,num,selectControl){
		this.num=num;
		this.element=$(selector).get(0);
		this.selectControl=selectControl;
	}
	SelectGroup.Select.prototype.init=function(){
		var self=this;
		$(this.element).bind("change",function(event){self.changeHandle(event)})
	}
	SelectGroup.Select.prototype.setData=function(data){
		this.data=data;
		var html="";
		var option=null
		
		this.element.length=0;
		for(var i in data){
			option = new Option(data[i].text,data[i].value);    
			this.element.options.add(option);   
		}
	}
	SelectGroup.Select.prototype.getSelectedData=function(value){
		var data=null;
		for(var i in this.data){
			if(this.data[i].value==value){
				data=this.data[i];
				break;
			}
		}
		return data;
	}
	SelectGroup.Select.prototype.changeHandle=function(event){
		var value=event.currentTarget.value;
		var selectedData=this.getSelectedData(value);
		if(selectedData!=null){
			this.selectControl(this.num+1,selectedData.children);
		}
	}
	SelectGroup.Select.prototype.focusOpen=function(){
		$(this.element).show();
	}
	SelectGroup.Select.prototype.focusClose=function(){
		this.setValue("")
		$(this.element).hide();
	}
	SelectGroup.Select.prototype.setValue=function(value){
		if(value==null){
			return ;
		}
		value=value.toString();
		this.setSelected(value);
	}
	SelectGroup.Select.prototype.setSelected=function(value){
		for (var i = 0; i < this.element.options.length; i++) {
			if (this.element.options[i].value == value) {        
				this.element.options[i].selected=true;       
			}        
		} 
	}
	
	
	
	/*
	
	Option
	
	*/
	
	SelectGroup.Select.Option=function(value,text){
		this.value=value;
		this.text=text;
	}
	SelectGroup.Select.Option.prototype.getHtml=function(){
		var html="<option value=\""+this.value+"\">"+this.text+"</option>"
		return html;
	}
	HTMLTurbo.control.SelectGroup=SelectGroup;
	var AttachmentView=function(selector){
		this.selector=selector;
	}
	AttachmentView.prototype=new Control();
	AttachmentView.prototype.init=function(){
		this.value=$(this.selector).val();
		this.create();
	}
	AttachmentView.prototype.create=function(){
		this.container=$("<div class=\"ht-attachmentView\"></div>").get(0);
		
		var valueArray=this.value.split(",");
		//console.log(valueArray);
		for(var i=0;i<valueArray.length;i++){
			var attachmentItem=new AttachmentItem(valueArray[i]);
			attachmentItem.init();
			
			$(this.container).append(attachmentItem.getElement());
		}
		$(this.selector).after(this.container);
	}
	AttachmentView.prototype.getElement=function(){
		return this.element;
	}
	
	var AttachmentItem=function(value){
		this.value=value;
	}
	AttachmentItem.prototype.element=null;
	AttachmentItem.prototype.init=function(){
		this.create();
	}
	AttachmentItem.prototype.create=function(){
		var valueArray=this.value.split("|");
		
		if(valueArray.length>1){
			var serverFileName=valueArray[0]
			var sourceFileName=valueArray[1]
			serverFileName=encodeURI(serverFileName)
			sourceFileName=encodeURI(sourceFileName)
			var href="/content/uploadFiles/"+serverFileName;
			href="/base/file/download.do?fileType=upload&fileName="+serverFileName+"&sourceFileName="+sourceFileName;
			this.element=$("<div><a href=\""+href+"\" target=\"_blank\"><span class=\"icon xls\"></span><span class=\"fileName\">"+sourceFileName+"</span></a></div>").get(0)
		}
	}
	AttachmentItem.prototype.getElement=function(){
		return this.element;
	}
	HTMLTurbo.control.AttachmentView=AttachmentView;
	// SearchGroup 选项组
	var SearchItem=function(template,source){
		this.template=template
		this.source=source;
	}
	SearchItem.prototype.init=function(){
		this.create();
	}
	SearchItem.prototype.template=""
	SearchItem.prototype.create=function(){
		var html=this.template
		this.selector=$(html);
		this.selector.get(0).className="searchItem";
		console.log(this.selector);
		
		var itemRelation=this.source.itemRelation;
		var field=this.source.field;
		var relation=this.source.relation;
		var value=this.source.value;
		
		$("input[name='itemRelation']",this.selector).val(itemRelation);
		$("select[name='field'] option[value='"+field+"']",this.selector).attr("selected", true); 
		$("select[name='relation'] option[value='"+relation+"']",this.selector).attr("selected", true); 
		$("input[name='value']",this.selector).val(this.source.value);
	}
	SearchItem.prototype.getElement=function(){
		return $(this.selector).get(0);
	}
	
	var SearchGroup=function(selector){
		this.selector=selector;
	}
	SearchGroup.prototype.init=function(){
		this.create();
	}
	SearchGroup.prototype.itemList=new Array();
	SearchGroup.prototype.create=function(){
		var sourceSearchItemList=$(".source .searchItem",this.selector)
		var sourceSearchItem=null;
		var sourceList=new Array();
		var source=null;
		
		var relation="";
		var field="";
		var source="";
		var value="";
		
		for(var i=0;i<sourceSearchItemList.length;i++){
			var sourceSearchItem=sourceSearchItemList[i]
			var source={
				itemRelation:$("input[name='itemRelation']",sourceSearchItem).val(),
				field:$("input[name='field']",sourceSearchItem).val(),
				relation:$("input[name='relation']",sourceSearchItem).val(),
				value:$("input[name='value']",sourceSearchItem).val()
			}
			sourceList.push(source);
		}
		this.searchItemTemplate=$(".searchItemTemplate",this.selector).eq(0).prop("outerHTML");
		$(".searchItemTemplate",this.selector).remove();
		$(".source",this.selector).remove();
		for(var i=0;i<sourceList.length;i++){
			source=sourceList[i]
			item=this.addItem(source.itemRelation,source);
		}
	}
	SearchGroup.prototype.addItem=function(type,source){
		var template=this.searchItemTemplate;
		var item=new SearchItem(this.searchItemTemplate,source);
		item.init();
		$(this.selector).append(item.getElement());
		if(type=="and"){
			$(item.getElement()).addClass("and");
			$(".removeButton",item.getElement()).addClass("and");
			$(".removeButton",item.getElement()).val("且");
			
			$("input[name='itemRelation']",item.getElement()).val("and");
		}
		if(type=="or"){
			$(item.getElement()).addClass("or");
			$(".removeButton",item.getElement()).addClass("or");
			$(".removeButton",item.getElement()).val("或");
			
			$("input[name='itemRelation']",item.getElement()).val("or");
		}
		
		var self=this;
		$(".addButton",item.getElement()).bind("click",function(event){
			var target=event.currentTarget;
			var value=target.value;
			
			
			var source={
				itemRelation:"",
				field:"",
				relation:"",
				value:""
			}
			if(value=="且"){
				self.addItem("and",source);
			}else{
				self.addItem("or",source);
			}
		});
		$(".removeButton",item.getElement()).bind("click",function(event){
			var target=event.currentTarget;
			self.removeItem(target);
		});
		this.update();
	}
	SearchGroup.prototype.removeItem=function(target){
		$(target).parent().remove();
		this.update();
	}
	SearchGroup.prototype.update=function(){
		var searchItemList=$(".searchItem",this.selector)
		var total=searchItemList.length;i
		var searchItem=null;
		for(var i=0;i<searchItemList.length;i++){
			searchItem=searchItemList[i]
			if(i==0){
				console.log(1);
				$(searchItem).addClass("first");
			}
			if(i<total-1){
				$(searchItem).removeClass("last");
			}
			if(i==total-1){
				$(searchItem).addClass("last");
			}
		}
	}
	HTMLTurbo.control.SearchGroup=SearchGroup;
	// Form 表单
	var Form=function(selector){
		this.selector=selector;
		this.element=$(selector).get(0);
	}
	Form.prototype=new Control();
	
	Form.prototype.ruleUrl="./formRule.json";
	Form.prototype.init=function(){
		//关闭验证 测试
		//return false;
		var self=this;
		$(this.selector).bind("submit",function(event){return self.submitHandler(event)})

		this.ruleParser=new RuleParser(this.selector);
		this.ruleParser.loadRule(this.ruleUrl);
	}
	Form.prototype.preSubmitHandler=function(){
		return true;
	}
	Form.prototype.submitHandler=function(event){
		if(!this.preSubmitHandler()){
			return false;
		}
		var self=this;
		try{
			var success=this.ruleParser.validate();
			if(!success){
				//输出提示
				var result=this.ruleParser.validateResult;
				var tips=result.getResultListFailTips();
				alert(tips);
				
				//设置焦点
				var resultList=result.resultList
				for(var i=0;i<resultList.length;i++){
					if(resultList[i].event=="eventFail"){
						var name=resultList[i].target
						$("[name='"+name+"']",this.selector).focus();
						break;
					}
				}
				return false;
			}
			//alert("提交成功");
			//return false;
			return true;
		}catch(e){
			console.log(e);
			alert("提交失败");
			return false;
		}
		return true;
	}
	HTMLTurbo.control.Form=Form;
	// Console 控制台
	var Console=function(selector,options){
		this.init();
	}
	Console.prototype.init=function(){
		this.create();
	}
	Console.prototype.create=function(){
	}
	Console.prototype.log=function(content){
		console.log(content);
	}
	Console.prototype.reset=function(){
	}
	HTMLTurbo.control.Console=Console;
	// Container 容器
	var Container=function(selector,options){
	}
	Container.prototype=new Control();
	Container.prototype.init=function(){
	}
	Container.prototype.reset=function(){
	}
	HTMLTurbo.control.Container=Container;
	// Bridge 桥
	var Bridge=function(){
	}
	Bridge.prototype=new Control();
	Bridge.prototype.init=function(){
		this.create();
	}
	Bridge.prototype.create=function(){
		this.selector=$("<iframe name=\"bridge\" style=\"display:none;\"></iframe>").get(0);
		this.element=$(this.selector).get(0);
		
		$(document.body).append(this.selector)
	}
	Bridge.prototype.get=function(url){
		this.selector.src=url;
	}
	Bridge.prototype.post=function(url,dataList){
		var html="";
		for(var i=0;i<dataList.lenght;i++){
			var data=dataList[0];
			var name=data.name;
			var value=data.value;
			html+="<input name=\""+name+"\" value=\""+value+"\" />";
		}
		var form=$("<form target=\"bridge\" action=\""+url+"\"></form>");
	}
	HTMLTurbo.control.Bridge=Bridge;
	// Masker 遮罩
	var Masker=function(selector){
		this.selector=selector;
		this.element=$(selector).get(0);
	}
	Masker.prototype=new Control();
	Masker.prototype.init=function(){
		if(typeof this.element=="undefined"){
			this.create();
		}
	}
	Masker.prototype.create=function(){
		this.element=document.createElement("div")
		this.element.className="ht-Masker"
		this.element.style.display="none"
		this.setId(this.id);
		document.body.appendChild(this.element)
	}
	Masker.prototype.open=function(){
		if(typeof this.element=="undefined"){
			this.create();
		}
		this.element.className="ht-Masker open";
		$(this.element).show();
	}
	Masker.prototype.close=function(){
		this.element.className="ht-Masker close";
		$(this.element).hide();
	}
	Masker.prototype.hide=function(){
		$(this.element).hide();
	}
	HTMLTurbo.control.Masker=Masker;
	// Loading 读取中
	var Loading=function(selector){
		this.selector=selector;
		this.element=$(selector).get(0);
		if(typeof this.element!="undefined"){
			this.isOpen=true;
		}
	}
	Loading.prototype=new Control();
	
	Loading.prototype.masker=null;
	Loading.prototype.element=null;
	Loading.prototype.tips=null;
	Loading.prototype.wrapper=null;
	Loading.prototype.isOpen=false;
	
	Loading.prototype.create=function(){
		var self=this;
		this.element=document.createElement("div");
		this.element.className="ht-Loading close";
		
		this.tips=document.createElement("p");
		this.tips.innerHTML="请稍候";
		
		this.wrapper=document.createElement("div");
		this.wrapper.className="wrapper";
		this.wrapper.appendChild(this.tips);
		
		this.setId(this.id);
		this.element.appendChild(this.wrapper);
		document.body.appendChild(this.element)
	}
	Loading.prototype.setElement=function(element){
		this.element=element;
		this.isOpen=true;
	}
	Loading.prototype.setMasker=function(masker){
		this.masker=masker;
	}
	Loading.prototype.open=function(){
		if(this.isOpen){
			return false;
		}
		var self=this;
		
		//masker
		if(this.masker==null){
			this.masker=new Masker();
		}else{
			//console.log("masker have");
		}
		this.masker.open()
		
		//loading
		if(this.element==null){
			this.create();
		}else{
			//console.log("loading have");
		}
		$(this.element).show();
		
		
		setTimeout(function(){
			self.element.className="ht-Loading open"
		},0)
		this.isOpen=true;
		return this;
	}
	Loading.prototype.close=function(){
		if(!this.isOpen){
			return false;
		}
		if(this.masker!=null){
			this.masker.close()
		}
		var self=this;
		if(this.element!=null){
			this.element.className="ht-Loading close"
			var timer=setTimeout(function(){
				//self.remove();
				$(self.element).hide();
				self.isOpen=false;
			},500);
		}
	}
	Loading.prototype.hide=function(){
		$(this.element).hide();
		this.masker.hide()
	}
	/*Loading.prototype.remove=function(){
		$(this.element).remove();
		
		//this.element.parentNode.removeChild(this.element)
		this.element=null;
		this.masker=null;
		//document.body.removeChild(this.element)
	}*/
	HTMLTurbo.control.Loading=Loading;
	// ProgressBar 进度条
	var ProgressBar=function(selector,options){
	}
	ProgressBar.prototype=new Control();
	ProgressBar.prototype.init=function(){
	}
	HTMLTurbo.control.ProgressBar=ProgressBar;
	// LetterCatalog 字母目录
	var LetterCatalog=function(selector){
		this.selector=selector;
	}
	LetterCatalog.prototype=new Control();
	LetterCatalog.prototype.init=function(){
		var self=this;
		$(".letterList a",this.selector).bind("click",function(event){
			var target=event.currentTarget;
			var text=target.innerHTML;
			
			self.setLetter(text);
		})
	}
	LetterCatalog.prototype.setLetter=function(letter){
		if(letter=="全部"){
			var className="ht-letterCatalog showLetterAll";
		}else{
			var className="ht-letterCatalog showLetter"+letter;
		}
		$(this.selector).get(0).className=className;
	}
	HTMLTurbo.control.LetterCatalog=LetterCatalog;
	//信使
	var Messager=function(selector){
		this.selector=selector;
	}
	Messager.prototype.url="./content.json";
	Messager.prototype.timer=null;
	Messager.prototype.count=0;
	
	Messager.prototype.content="<p>暂无消息</p>";
	Messager.prototype.delay=1000;
	Messager.prototype.init=function(){
		if(typeof this.selector == "undefined"){
			this.create();
		}
		var self=this;
		this.testing();
		this.timer=setInterval(function(event){
			self.testing();
		}, this.delay);
		$(".closeButton",this.selector).bind("click",function(event){
			self.focusClose();
		});
		$(".openButton",this.selector).bind("click",function(event){
			self.focusOpen();
		});
		//this.update();
	}
	Messager.prototype.create=function(){
		var html='';
		html+='<div class="ht-messager focusClose" id="messager">';
		html+='<div class="wrapper">';
		html+='<h4 class="title">消息提醒  <strong class="count">[0]</strong></h4>';
		html+='<div class="toolBar">';
		html+='<a class="button closeButton">关闭</a><a class="button openButton">打开</a>';
		html+='</div>';
		html+='<div class="content">';
		html+='<p>暂无内容</p>';
		html+='</div>';
		html+='</div>';
		html+='</div>';
		this.selector=$(html)
		$("body").append(this.selector);
	}
	Messager.prototype.update=function(){
		$(".content",this.selector).html(this.content);
		$(".count",this.selector).html("["+this.count+"]");
		ht.update($(".content",this.selector));
		if(this.count==0){
			this.focusClose();
		}else{
			this.focusOpen();
		}
	}
	Messager.prototype.testing=function(){
		var self=this;
		var options={}
		options.url=this.url;
		options.dataType="json"
		options.cache=false
		options.type="get"
		options.success=function(data, textStatus, jqXHR){
			
			var updateEnable=false;
			var content=data.data.content;
			var count=data.data.count;
			
			if(self.content!=content){
				updateEnable=true;
			}
			if(self.count!=count){
				updateEnable=true;
			}
			
			self.content=content;
			self.count=count;
			
			if(updateEnable){
				self.update();
			}
		},
		options.error=function(){
			$(".title",this.selector).html("刷新消息失败");
		}
		$.ajax(options);
	}
	Messager.prototype.focusOpen=function(){
		//console.log(11);
		$(this.selector).removeClass("focusClose");
		$(this.selector).addClass("focusOpen");
	}
	Messager.prototype.focusClose=function(){
		//console.log(22);
		$(this.selector).removeClass("focusOpen");
		$(this.selector).addClass("focusClose");
	}
	HTMLTurbo.control.Messager=Messager;
	// Dialog 对话框
	var Dialog=function(selector){
		this.element=$(selector).get(0)
		if(this.element!=null){
			this.init();
		}
	}
	Dialog.prototype=new Control();
	Dialog.prototype.create=function(){
		var html="<section class=\"ht-dialogContent\" id=\"noticeDialog\"><div class=\"wrapper\"><h4 class=\"title\">提示标题</h4><a class=\"ht-CloseButton\">close</a<div class=\"content\"><p>提示标题</p></div></div></section>"
		var element=$(html);
		return element;
	}
	Dialog.prototype.init=function(){
		var title=this.getTitle()
		var self=this;
		$(this.element).removeClass("ht-dialogContent")
		$(this.element).addClass("ht-Dialog")
		
		if(title!="" && title!="请求处理成功"){
			//this.element.className="dialog close"
			$(this.element).addClass("close")
			setTimeout(function(){self.open();ht.masker.open()} ,50)
			//setTimeout(function(){self.close()} ,5000)
		}else{
			this.element.style.display="none"
		}
		$(".ht-CloseButton",this.element).bind("click",function(event){self.closeButtonClickHandle(event);})
		$("form").bind("click",function(event){self.closeButtonClickHandle(event);})
	}
	Dialog.prototype.closeButtonClickHandle=function(event){
		this.close();
	}
	
	Dialog.prototype.getTitle=function(){
		var title=""
		try{
			title=this.element.children[0].children[0].innerHTML
		}catch(error){
			console.log("no title element")
		}
		return title;
	}
	Dialog.prototype.open=function(){
		//alert("open");
		//this.element.className="dialog open"
		$(this.element).removeClass("close")
		$(this.element).addClass("open")
		this.element.style.display="block"
		//$(this.element).animate({opacity:'100'},500);
		return this;
	}
	Dialog.prototype.close=function(){
		//alert("close");
		//this.element.className="dialog close"
		$(this.element).removeClass("open")
		$(this.element).addClass("close")
		var self=this;
		$(this.element).stop()
		setTimeout(function(){
			self.element.style.display="none"
		} ,500)
        ht.masker.close();
		/*$(this.element).animate({opacity:'0'},500,function(){
			self.element.style.display="none"
			//$(self.element).hide()
		});*/
		return this;
	}
	HTMLTurbo.control.Dialog=Dialog;
	// FrameWindow 框架窗口
	var FrameWindow = function() {}
	FrameWindow.prototype=new Control();
	
	FrameWindow.left = 50
	FrameWindow.top = 50
	FrameWindow.zIndex = 5000;
	FrameWindow.prototype.left = 50;
	FrameWindow.prototype.top = 50;
	FrameWindow.prototype.opened = false;
	FrameWindow.prototype.sizeType = "";
	FrameWindow.prototype.create = function() {
		var self = this;
		this.element = document.createElement("div");
		this.element.className = "ht-FrameWindow " + this.sizeType + " close";
		//this.element.style.zIndex = FrameWindow.zIndex;
	
		this.left = FrameWindow.left
		this.top = FrameWindow.top
	
		if (this.sizeType != "fullScreen") {
			this.element.style.left = this.left + "%";
			this.element.style.top = this.top + "%";
		}
	
		this.wrapper = document.createElement("div");
		this.wrapper.className = "wrapper"
		this.title = document.createElement("h4");
		this.title.className = "title"
		this.title.innerHTML = ""
	
		this.closeButton = document.createElement("a")
		this.closeButton.className = "ht-CloseButton"
		this.closeButton.innerHTML = "关闭"
	
		this.iframe = document.createElement("iframe")
		this.iframe.frameBorder = 0;
		this.iframe.scrolling = "yes";
		// this.iframe.src="/orfp/base/account/selector.html"
	
		this.element.appendChild(this.wrapper)
		this.wrapper.appendChild(this.title)
		this.wrapper.appendChild(this.closeButton)
		this.wrapper.appendChild(this.iframe)
		this.mouseMoveActionHelper=function(e){
			var e=e||window.event;
			self.wrapper.style.left=self.recordX+(e.clientX-self.mouseStartX)+"px";
			self.wrapper.style.top=self.recordY+(e.clientY-self.mouseStartY)+"px";
		}
		this.mouseMoveAction=function(e){
			$(self.title).bind("mousedown",function(e){
				var e=e||window.event;
				self.recordX=$(self.wrapper).position().left;
				self.recordY=$(self.wrapper).position().top;
				self.mouseStartX=e.clientX;
				self.mouseStartY=e.clientY;
				$(self.wrapper).bind("mousemove",self.mouseMoveActionHelper);
				$(self.title).css("cursor","move");
			});
			$(self.wrapper).bind("mouseup",function(e){
				$(self.wrapper).unbind("mousemove",self.mouseMoveActionHelper);
				$(self.title).css("cursor","default");
			})
			$(self.wrapper).bind("mouseout",function(e){
				try{
					$(self.wrapper).unbind("mousemove",self.mouseMoveActionHelper);
					$(self.title).css("cursor","default");
				}catch(error){
					console.log(error);
				}
			})
		}
		
	
		if(this.sizeType != "fullScreen"){
			self.mouseMoveAction();
		}else{
			/*var cHeight=$(document.body).height()-20-57;
			self.iframe.style.height=cHeight+"px";
			
			$(window).bind("resize",function(event){
				var cHeight=$(document.body).height()-20-57;
				self.iframe.style.height=cHeight+"px";
				return true;
			})*/
		}
		document.body.appendChild(this.element)
		$(this.closeButton).bind("click", function(event) {
			self.closeButtonClickHandler(event)
		})
		$(this.element).bind("click", function(event) {
			self.clickHandle(event)
		})
	}
	FrameWindow.prototype.clickHandle = function(event) {
		this.zIndexUp();
	}
	
	FrameWindow.prototype.closeButtonClickHandler = function(event) {
		this.close();
	}
	
	
	// z轴上升
	FrameWindow.prototype.zIndexUp = function() {
		FrameWindow.zIndex++
		this.element.style.zIndex = FrameWindow.zIndex;
	}
	
	// 关闭
	FrameWindow.prototype.close = function() {
		clearInterval(this.updateTitleTimer);
	
		if (this.opened == false) {
			return false;
		}
		this.element.className = "ht-FrameWindow " + this.sizeType + " close";
		this.element.style.top = (this.top + 2) + "%";
		window.ht.masker.close()
		var self = this;
		// self.remove();
		var timer = setTimeout(function() {
			self.remove();
		}, 500);
		this.wrapper.removeChild(this.iframe)
		// $(this.element).animate({opacity:'0'},"fast");
		// document.body.removeChild(this.element)
		this.opened = false;
	
		if (FrameWindow.left > 50) {
			FrameWindow.left -= 1
			FrameWindow.top -= 3
			//FrameWindow.zIndex++;
		} else {
			FrameWindow.left = 50
			FrameWindow.top = 50
		}
		try {
			top.content.baseContent.focus();
		} catch (error) {
	
		}
	}
	
	// 打开
	FrameWindow.prototype.open = function(src,titleStr,sizeType,launchParentFrameWindow) {
	
		//因为a title设置不准确不可开启
		titleStr="";
		this.titleStr=titleStr;
		if (typeof (sizeType) != "undefined") {
			this.sizeType = sizeType;
		}
		if (src == "" || typeof (src) == "undefined" || src == null) {
			return false;
		}
		if (src.indexOf("%7B") != "-1") {
			return false;
		}
	
		var self = this;
		window.ht.masker.open()
	
		this.create();
		this.title.innerHTML = "";
		
		if(this.titleStr!="" && this.titleStr!=null){
			this.title.innerHTML = this.titleStr;
		}
		
		this.launchParentFrameWindow = launchParentFrameWindow;
		var self = this;
		setTimeout(function() {
			self.element.className = "ht-FrameWindow " + self.sizeType + " open"
			if (self.sizeType != "fullScreen") {
				self.element.style.top = self.top + "%";
			}
			//$(self.element).addClass("ht-window-fullScreen");
			self.opened = true;
		}, 0)
		setTimeout(function() {
			if (src.indexOf("?") == -1) {
				src += "?"
			}
			src += "&_=" + Math.round(Math.random() * 1000);
			self.iframe.src = src
			// self.connectTimer=setInterval(function(){self.connectIFrame()},500);
		}, 200)
	
		this.updateTitleTimer = setInterval(function() {
			try{
				self.updateTitle()
			}catch(error){
			};
		}, 1000)
	
		if (FrameWindow.left < 55) {
			FrameWindow.left += 1
			FrameWindow.top += 3
		} else {
			FrameWindow.left = 50
			FrameWindow.top = 50
		}
	
		return this;
	}
	
	// 隐藏
	FrameWindow.prototype.hide=function(){
		$(this.element).hide();
		window.ht.masker.close()
	}
	
	
	// 更新标题
	FrameWindow.prototype.updateTitle = function() {
		if(this.titleStr=="" || this.titleStr==null){
			if (this.iframe.contentWindow.document.body != null) {
				this.title.innerHTML = this.iframe.contentWindow.document.title
			}
		}
	}
	
	// 连接iframe
	FrameWindow.prototype.connectIFrame = function() {
		if (this.iframe.contentWindow != null) {
			if (this.iframe.contentWindow.document.body != null) {
				this.iframe.contentWindow.launchParentFrameWindow = this.launchParentFrameWindow
				this.title.innerHTML = this.iframe.contentWindow.document.title
				clearInterval(this.connectTimer)
				// console.log(this.iframe.launchParentFrameWindow)
	
				// $(this.element).animate({opacity:'1'},"fast");
			}
		}
	}
	
	// 移除
	FrameWindow.prototype.remove = function() {
		this.element.parentNode.removeChild(this.element)
		//document.body.removeChild(this.element)
		clearInterval(this.updateTitleTimer)
	}
	
	HTMLTurbo.control.FrameWindow=FrameWindow;
	// SafeCode 安全码
	var SafeCode=function(selector,options){
		this.selector=selector;
		this.element=$(this.selector).get(0);
		this.imgElement=this.element.children[0]
	}
	SafeCode.prototype=new Control();
	SafeCode.prototype.init=function(){
		this.src=$(this.imgElement).attr("src");
		var self=this;
		$(this.imgElement).bind("click",function(event){
			self.clickHandler(event);
		});
	}
	SafeCode.prototype.reset=function(){
		this.imgElement.src=this.src+"?_="+Math.random()
	}
	SafeCode.prototype.clickHandler=function(event){
		this.reset();
	}
	HTMLTurbo.control.SafeCode=SafeCode;
	// Tabs 菜单卡
	var Tabs=function(selector,options){
		this.setSelector(selector);
		this.setElement($(this.selector).get(0));
	}
	Tabs.prototype=new Control();
	Tabs.prototype.init=function(){
		var self=this;
		
		var selector=$(".tabsList",this.element).get(0);
		this.tabsList=new Tabs.TabsList(selector,function(focusNum){self.setFocusNum(focusNum);});
		this.tabsList.init()
		
		var selector=$(".tabsContentGroup",this.element).get(0);
		this.tabsContentGroup=new Tabs.TabsContentGroup(selector,function(focusNum){self.setFocusNum(focusNum);});
		this.tabsContentGroup.init();
		this.setFocusNum(0);
	}
	Tabs.prototype.setFocusNum=function(focusNum){
		this.focusNum=focusNum;
		this.tabsList.setFocusNum(focusNum);
		this.tabsContentGroup.setFocusNum(focusNum);
	}
	
	
	//TabsList
	Tabs.TabsList=function(selector,parentSetFoucsNum){
		this.selector=selector;
		this.parentSetFoucsNum=parentSetFoucsNum;
	}
	Tabs.TabsList.prototype.init=function(){
		var items=$("li",this.selector)
		var listItemList=new Array();
		var listItem=null;
		var selector=null;
		var self=this;
		for(var i=0;i<items.length;i++){
			selector=items.get(i);
			listItem=new Tabs.TabsListItem(selector,i,function(focusNum){self.parentSetFoucsNum(focusNum)});
			listItem.init();
			listItemList.push(listItem);
		};
		this.listItemList=listItemList;
	}
	Tabs.TabsList.prototype.focusNum=0;
	Tabs.TabsList.prototype.setFocusNum=function(focusNum){
		this.focusNum=focusNum;
		
		var listItemList=this.listItemList;
		for(var i=0;i<listItemList.length;i++){
			listItemList[i].focusClose();
		}
		listItemList[focusNum].focusOpen();
	}
	
	
	//TabsListItem
	Tabs.TabsListItem=function(selector,num,parentSetFoucsNum){
		this.selector=selector;
		this.num=num;
		this.parentSetFoucsNum=parentSetFoucsNum;
	}
	Tabs.TabsListItem.prototype.init=function(){
		var self=this;
		$(this.selector).bind("click",function(){
			self.parentSetFoucsNum(self.num);
		});
	}
	Tabs.TabsListItem.prototype.focusOpen=function(){
		$(this.selector).removeClass("focusClose").addClass("focusOpen");
	}
	Tabs.TabsListItem.prototype.focusClose=function(){
		$(this.selector).removeClass("focusOpen").addClass("focusClose");
	}
	
	
	
	//TabsContentGroup
	Tabs.TabsContentGroup=function(selector,parentSetFoucsNum){
		this.selector=selector;
		this.parentSetFoucsNum=parentSetFoucsNum;
	}
	Tabs.TabsContentGroup.prototype.init=function(){
		var items=$(".tabsContent",this.selector)
		var listItemList=new Array();
		var listItem=null;
		var selector=null;
		
		for(var i=0;i<items.length;i++){
			selector=items.get(i);
			listItem=new Tabs.TabsContent(selector,i);
			listItem.init();
			listItemList.push(listItem);
		};
		this.listItemList=listItemList;
	}
	Tabs.TabsContentGroup.prototype.focusNum=0;
	Tabs.TabsContentGroup.prototype.setFocusNum=function(focusNum){
		this.focusNum=focusNum;
		var listItemList=this.listItemList;
		for(var i=0;i<listItemList.length;i++){
			listItemList[i].focusClose();
		}
		if(listItemList.length>focusNum){
			listItemList[focusNum].focusOpen();
		}else{
			listItemList[0].focusOpen();
		}
	}
	
	//TabsContent
	Tabs.TabsContent=function(selector){
		this.selector=selector;
	}
	Tabs.TabsContent.prototype.init=function(){
	}
	Tabs.TabsContent.prototype.focusOpen=function(){
		$(this.selector).removeClass("focusClose").addClass("focusOpen");
	}
	Tabs.TabsContent.prototype.focusClose=function(){
		$(this.selector).removeClass("focusOpen").addClass("focusClose");
	}
	HTMLTurbo.control.Tabs=Tabs;
	var Accordion=function(selector){
		this.selector=selector;
		this.element=$(selector).get(0);
		
		this.init();
	}
	Accordion.prototype=new Control();
	Accordion.prototype.init=function(){
		this.list=new Accordion.List(this.element.children[0]);
		//this.list.focusControl(0);
	}
	Accordion.prototype.setFocusNum=function(focusNum){
		this.list.setFocusNum(focusNum);
	}
	
	
	
	
	Accordion.List=function(selector){
		this.selector=selector
		this.element=$(selector).get(0);
		this.init();
	}
	Accordion.List.prototype=new FocusList()
	Accordion.List.prototype.init=function(){
		this.create();
	}
	Accordion.List.prototype.create=function(){
		var children=this.element.children;
		var item=null;
		var self=this;
		this.items=new Array()
		for(var i=0;i<children.length;i++){
			item=new Accordion.ListItem(children[i],i,function(focusNum){self.setFocusNum(focusNum);});
			item.init();
			this.items.push(item);
		}
	}
	
	Accordion.ListItem=function(selector,num,setFocusNum){
		this.selector=selector;
		this.num=num;
		this.setFocusNum=setFocusNum;
	}
	Accordion.ListItem.prototype=new FocusListItem()
	Accordion.ListItem.prototype.init=function(){
		
		this.element=$(this.selector).get(0);
		
		var self=this;
		$("div.accordionTitle",this.element).bind("click",function(event){self.clickTitleHandle(event)})
	}
	Accordion.ListItem.prototype.create=function(){	
	}
	Accordion.ListItem.prototype.clickTitleHandle=function(event){
		this.setFocusNum(this.num);
	}
	Accordion.ListItem.prototype.focusOpen=function(){
		this.element.className="focusOpen";
	};
	Accordion.ListItem.prototype.focusClose=function(){
		this.element.className="focusClose";
	};
	
	HTMLTurbo.control.Accordion=Accordion;
	// Pagination 分页
	var Pagination=function(selector,options){
	}
	Pagination.prototype=new Control();
	Pagination.prototype.init=function(){
	}
	HTMLTurbo.control.Pagination=Pagination;
	// Nav 导航
	var Nav=function(selector,options){
	}
	Nav.prototype=new Control();
	Nav.prototype.init=function(){
	}
	HTMLTurbo.control.Nav=Nav;
	// AsynList 异步列表
	var AsynList=function(selector){
		this.page=$("[name=page]").val();
		this.cache=$("#cache",this.selector).val();
		
		$(".container ul",this.selector).eq(0).append(this.cache);
	}
	AsynList.prototype=new Control();
	AsynList.prototype.cache="";
	AsynList.prototype.page=0;
	AsynList.prototype.init=function(){
		var self=this;
		$(".listMoreButton",this.selector).bind("click",function(event){
			self.load();
		})
		if(this.page==""){
			this.load();
		}else{
			this.updateMoreButton();
		}
	}
	AsynList.prototype.setItemTemplate=function(itemTemplate){
		this.itemTemplate=itemTemplate;
	}
	AsynList.prototype.load=function(){
		var page=$("[name=page]").val();
		if(page=="" || page==0){
			page=1;
		}else{
			page++;
		}
		$("[name=page]").val(page);

		var url=$(this.selector).attr("action");
		var method=$(this.selector).attr("method");
		var data=$(this.selector).serializeArray();
		var self=this;
		var options={}
		options.url=url
		options.dataType="json"
		options.cache=false
		options.type=method
		options.data=data
		options.success=function(data, textStatus, jqXHR){
			self.loadSuccess(data);
		},
		options.error=function(){
			alert("操作失败");
		}
		$.ajax(options);
	}
	AsynList.prototype.loadSuccess=function(data){
		var event=data.event;
		var tips=data.tips;

		if(event=="success"){
			var html=this.render(data.data);
		}
		if(event=="fail"){
			alert(tips);
		}
	}
	AsynList.prototype.updateMoreButton=function(){
		var more=$("#more").val();
		if(more==1){
			$(".listMoreButton",this.selector).addClass("enable");
		}else{
			$(".listMoreButton",this.selector).removeClass("enable");
			$(".listMoreButton",this.selector).unbind("click")
		}
	}
	AsynList.prototype.render=function(data){
		var page=parseInt(data.page)
		var totalPage=parseInt(data.totalPage)
		
		if(page<totalPage){
			$("#more").val(1);
		}else{
			$("#more").val(0);
		}
		this.updateMoreButton();
		$("[name=page]").val(page);

		var rows=data.rows
		var temp="";
		var row=null;
		var html="";
		var regExp=new RegExp();
		for(var i=0;i<rows.length;i++){
			row=rows[i];
			var temp=this.itemTemplate;
			for(var key in row){
				var value=row[key];

				regExp=new RegExp("\{"+key+"\}","g");
				temp=temp.replace(regExp,value);
			}
			html+=temp;
		}
		var cache=$("#cache",this.selector).val()+html;
		$("#cache",this.selector).val(cache);
		
		$(".container ul",this.selector).eq(0).append(html);
	}
	HTMLTurbo.control.AsynList=AsynList;
	//Focus 焦点
	var Item=function(selector){
		this.selector=selector;
		this.element=$(selector).get(0);
	};
	var List=function(selector){
		Item.call(this,selector)
	};
	
	
	var Focus=function(selector){
		Item.call(this,selector)
		//console.log(selector);
	}
	Focus.prototype=new Control();
	Focus.prototype.focusNum=0;
	Focus.prototype.total=0;
	Focus.prototype.focusList=new Array();
	Focus.prototype.init=function(){
		this.create();
		this.focusList=new FocusList(this.element.children[0].children[0]);
		this.total=this.focusList.total;
		
		var self=this;
		$(".prevButton",this.selector).bind("click",function(event){
			self.prev();
		})
		$(".nextButton",this.selector).bind("click",function(event){
			self.next();
		})
		
		var container=$(".container",this.selector).get(0);
		var self=this;
		var startX=0;
		var startY=0;
		var touchX=0;
		
		$(container).bind("touchstart",function(event){
			//console.log("touchstart");
			var touch = event.originalEvent.touches[0], //获取第一个触点
				x = Number(touch.pageX), //页面触点X坐标
				y = Number(touch.pageY); //页面触点Y坐标
			//记录触点初始位置
			startX = x;
			startY = y;
		})
		$(container).bind("touchmove",function(event){
			var uWidth=document.body.clientWidth;
			var touch = event.originalEvent.touches[0]; //获取第一个触点
				x = Number(touch.pageX); //页面触点X坐标
				y = Number(touch.pageY); //页面触点Y坐标
				
			touchX=x - startX;
			var left=-(self.focusNum*uWidth)+touchX;
			//console.log(left);
			if(left<0 && left>-$("ul",self.selector).width()-uWidth){
				$("ul",self.selector).css({"left":left+"px"});
			}
		})
		$(container).bind("touchend",function(event){
			//console.log("touchEnd");
			//console.log(touchX);
			if(touchX>100){
				self.prev();
			}else if(touchX<-100){
				self.next();
			}else{
				self.setFocusNum(self.focusNum);
			}
		})
	}
	Focus.prototype.create=function(){
		var ul=$(this.selector).children(0);
		//var html="<div class=\"container\"></div><a class=\"prevButton\">prev</a><a class=\"nextButton\">next</a>"
		var html="<div class=\"container\"></div><a class=\"prevButton\">prev</a><a class=\"nextButton\">next</a>"
		$(this.selector).append(html)
		$(".container",this.selector).append(ul)
	}
	Focus.prototype.setFocusNum=function(focusNum){
		this.focusNum=focusNum;
		this.focusList.setFocusNum(this.focusNum);
	}
	Focus.prototype.prev=function(){
		//console.log("prev");
		if(this.focusNum>0){
			this.focusNum--;
		}else{
			this.focusNum=this.total-1;
		}
		this.setFocusNum(this.focusNum);
	}
	Focus.prototype.next=function(){
		//console.log("next");
		if(this.focusNum<this.total-1){
			this.focusNum++;
		}else{
			this.focusNum=0;
		}
		this.setFocusNum(this.focusNum);
	}
	
	
	
	
	
	
	
	FocusList=function(selector){
		List.call(this,selector)
		this.init();
	}
	FocusList.prototype.focusNum=0;
	FocusList.prototype.total=0;
	FocusList.prototype.itemList=new Array();
	FocusList.prototype.init=function(){
		this.create();
	}
	FocusList.prototype.create=function(){
		var children=this.element.children;
		this.total=children.length;
		for(var i=0;i<this.total;i++){
			this.itemList[i]=new FocusListItem(children[i]);
		}
	}
	FocusList.prototype.setFocusNum=function(focusNum){
		this.focusNum=focusNum;
		//console.log(this.focusNum);
		var uWidth=document.body.clientWidth;
		
		var left=-(focusNum*uWidth);
		$(this.element).animate({left:left+"px"});
		for(var i=0;i<this.total;i++){
			this.itemList[i].focusClose();
		}
		this.itemList[focusNum].focusOpen();
	}
	
	
	
	
	
	
	
	
	
	FocusListItem=function(selector){
		Item.call(this,selector)
	}
	FocusListItem.prototype.init=function(){}
	FocusListItem.prototype.update=function(){
	}
	FocusListItem.prototype.focusOpen=function(){
		this.element.className="focusOpen"
	}
	FocusListItem.prototype.focusClose=function(){
		this.element.className="focusClose"
	}
	HTMLTurbo.control.Focus=Focus;
	//日历
	var Calendar=function(selector,options){
		this.selector=selector;
		if(typeof options!="undefined"){
			this.options=$.extend({},this.getDefaultOptions(),options);
			this.dateStr=this.options.value;
		}else{
			this.options=$.extend({},this.getDefaultOptions());
		}
		this.dateStr=this.options.value;
		this.date=Utils.getDateByDateStr(this.dateStr);
	}
	Calendar.WEEK_DICT=["日","一","二","三","四","五","六"]
	Calendar.WEEK_DICT_CLASSNAME=["sun","mon","tues","wed","thurs","fri","sat"]
	
	Calendar.MONTH_DICT=["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]
	
	Calendar.prototype=new Control();
	Calendar.prototype.dateStr="";
	
	Calendar.options={
		startDate:"1900-1-1",
		startDateNotFitTips:"不得早于预定的起始时间",
		
		endDate:"2099-12-31",
		endDateNotFitTips:"不得晚于预定的结束时间",
		
		startSelector:"",
		startSelectorNotFitTips:"不得早于选择的起始时间",
		
		endSelector:"",
		endSelectorNotFitTips:"不得晚于选择的结束时间",
		
			
		monthInfoListUrl:"monthInfoList.do",
		setDate:function(date){
			
		}
	}
	Calendar.prototype.init=function(){
		this.year=this.date.getFullYear();
		this.month=this.date.getMonth();
		this.day=this.date.getDate();
		
		this.element=$(this.selector).get(0);
		this.element.className="ht-calendar";
		
		var content=this.element.innerHTML;
		this.element.innerHTML=""
		this.setContent(content);
		
		//this.styleElement=$("<link href=\"/common/HTMLTurbo/0.1.0/module/control/dateInput/common.css\" rel=\"stylesheet\" type=\"text/css\" />").get(0);
		
		var self=this;
		
		this.yearController=new Calendar.YearController(this.year,function(flag){self.switchYear(flag)});
		this.yearElement=this.yearController.getElement();
		
		this.monthController=new Calendar.MonthController(this.month,function(flag){self.switchMonth(flag);});
		this.monthElement=this.monthController.getElement();
		
		this.dayList=new Calendar.DayList(this.date,function(value){self.options.setDate(value)},this.infoList,this.options);
		this.dayListElement=this.dayList.getElement()
		
		//ht.update(this.dayListElement);
		
		this.weekList=new Calendar.WeekList();
		this.weekListElement=this.weekList.getElement()
		
		
		//this.element.appendChild(this.styleElement);
		this.element.appendChild(this.yearElement);
		this.element.appendChild(this.monthElement);
		this.element.appendChild(this.weekListElement);
		this.element.appendChild(this.dayListElement);
		
		this.endYear=this.options.endDate.split("-")[0]
		this.startYear=this.options.startDate.split("-")[0]
	}
	Calendar.prototype.infoList=null;
	Calendar.prototype.setContent=function(content){
		var itemList=$("li",content);
		var item=null;
		
		var infoList=new Array();
		var info={};
		
		var title="";
		var dateStr="";
		var date=null;
		var target="";
		
		for(var i=0;i<itemList.length;i++){
			item=itemList[i];
			title=$("a",item).attr("title");
			url=$("a",item).attr("href");
			dateStr=$(".dateTime",item).html();
			target=$("a",item).attr("target");
			//console.log(dateStr);
			
			date=Utils.getDateByDateStr(dateStr);//console.log(1);
			dateStr=Utils.getDateStr(date);
			
			info={
				title:title,
				url:url,
				dateStr:dateStr,
				date:date,
				target:target
			};
			infoList.push(info);
		}
		this.infoList=infoList;
		//console.log(infoList);
	};
	
	Calendar.prototype.getDefaultOptions=function(){
		var options=Calendar.options;
		
		var date=new Date();
		var dateStr=Utils.getDateStr(date)
		options.value=dateStr;
		
		return options;
	}
	Calendar.prototype.switchYear=function(flag){
		var endYear=this.endYear
		var startYear=this.startYear
		
		if(flag=="+"){
			if(endYear>this.year){
				this.year++;
			}else{
				return false;
			}
		}else{
			if(startYear<this.year){
				this.year--;
			}else{
				return false;
			}
		}
		this.update();
		return true;
	}
	Calendar.prototype.switchMonth=function(flag){
		if(flag=="+"){
			this.month++;
		}else{
			this.month--;
		}
		if(this.month==12){
			if(this.switchYear("+")){
				this.month=0;
			}else{
				this.month=11;
			}
		}
		if(this.month<0){
			if(this.switchYear("-")){
				this.month=11;
			}else{
				this.month=0;
			}
		}
		this.update();
	}
	Calendar.prototype.update=function(){
		this.yearController.setValue(this.year);
		this.monthController.setValue(this.month);
		this.dayList.setYearMonth(this.year,this.month);
	}
	Calendar.prototype.getElement=function(){
		return this.element;
	}
	
	
	
	
	
	
	//星期列表
	Calendar.WeekList=function(){
		this.init();
	}
	Calendar.WeekList.prototype.init=function(){
		this.element=document.createElement("ul");
		this.element.className="weekList";
		this.update();
	}
	Calendar.WeekList.prototype.update=function(){
		var total=7;
		var listItemArray=new Array();
		var listItem=null;
		
		for(var i=0;i<total;i++){
			listItem=new Calendar.WeekListItem(i);
			this.element.appendChild(listItem.getElement())
			listItemArray.push(listItem);
		}
	}
	Calendar.WeekList.prototype.getElement=function(){
		return this.element;
	}
	Calendar.WeekListItem=function(num){
		this.num=num;
		this.init();
	}
	Calendar.WeekListItem.prototype.init=function(){
		this.element=document.createElement("li")
		this.text=document.createElement("a")
		this.element.appendChild(this.text);
		this.update();
	}
	Calendar.WeekListItem.prototype.update=function(){
		var text=Calendar.WEEK_DICT[this.num];
		this.text.innerHTML=text;
		
		this.element.className=Calendar.WEEK_DICT_CLASSNAME[this.num]
	}
	Calendar.WeekListItem.prototype.getElement=function(){
		return this.element;
	}
	
	
	//日期列表
	Calendar.DayList=function(currentDate,setDate,infoList,options){
		this.currentDate=currentDate;
		
		this.year=this.currentDate.getFullYear();
		this.month=this.currentDate.getMonth();
		
		this.infoList=infoList;
		
		this.setDate=setDate
		
		this.options=options
		this.init();
	}
	Calendar.DayList.prototype.init=function(){
		this.element=document.createElement("ul");
		this.element.className="dayList"
		//this.update();
		
		this.setYearMonth(this.year,this.month);
	}
	Calendar.DayList.prototype.setYearMonth=function(year,month){
		this.year=year
		this.month=month;
		
		//var url="monthInfoList.json?year="+year+"&month="+month;
		//var url="monthInfoList.do?year="+year+"&month="+(month+1);
		var url=this.options.monthInfoListUrl
		url+="?year="+year+"&month="+(month+1);
		var self=this;
		var options={
			url: url,
			dataType:"json",
			cache:false,
			success: function(data, textStatus, jqXHR){
				//self.loadRuleSuccess(data);
				self.infoList=data;
				self.update();
			},
			error :function(){
				alert("rule load error ");
			}
		}
		$.ajax(options);
	}
	Calendar.DayList.prototype.update=function(){
		var self=this;
		
		var year=this.year;
		var month=this.month
		var day=0;
		
		var length=Utils.getYearMonthDayLength(year,month);
		var listItemArray=new Array();
		var listItem=null;
		
		this.element.innerHTML="";
		var listItemElement=null;
		
		var firstDate=Utils.getDate(year,month,day+1);
		var week=firstDate.getDay();
		var date=null;
		for(var i=0;i<week;i++){
			this.element.appendChild($("<li><a></a></li>").get(0));
		}
		for(var i=0;i<length;i++){
			date=Utils.getDate(this.year,this.month,i+1);
			listItem=new Calendar.DayListItem(i,date,this.currentDate,function(num){self.focusControl(num);},this.infoList);
			listItemArray.push(listItem);
			listItemElement=listItem.getElement()
			
			this.element.appendChild(listItemElement);
		}
		ht.update(this.element);
	}
	Calendar.DayList.prototype.focusControl=function(num){
		var date=Utils.getDate(this.year,this.month,num+1);
		this.setDate(date);
	}
	Calendar.DayList.prototype.getElement=function(){
		return this.element;
	}
	
	Calendar.DayListItem=function(num,date,currentDate,focusControl,infoList){
		this.num=num;
		this.focusControl=focusControl;
		this.date=date;
		this.currentDate=currentDate;
		this.infoList=infoList;
		
		this.init();
	}
	Calendar.DayListItem.prototype.getInfo=function(){
		var infoList=this.infoList;
		var info=null;
		var date=null;
		
		for(var i=0;i<infoList.length;i++){
			info=infoList[i];
			//var dateStr=Utils.getDateStr(date)
			date=Utils.getDateByDateStr(info.date);
			//console.log(date);
			//info.date=Utils.getDateByDateStr(info.date);
			//console.log(Utils.getDateStr(date));
			//console.log(Utils.getDateStr(this.date));
			//console.log(info.date==this.date);
			if(Utils.getDateStr(date)==Utils.getDateStr(this.date)){
				return info;
			}
		}
		return null;
	}
	Calendar.DayListItem.prototype.init=function(){
		this.element=document.createElement("li")
		this.aElement=document.createElement("a")
		
		this.infoElement=document.createElement("span")
		this.infoElement.className="info";
		
		var info=this.getInfo();
		//console.log(info);
		if(info!=null){
			$(this.aElement).attr("href",info.url);
			$(this.aElement).attr("title",info.title);
			$(this.aElement).attr("target",info.target);
			
			this.element.className="info"
		}
		this.element.className+=" "+Calendar.WEEK_DICT_CLASSNAME[this.date.getDay()]
		if(this.date.getTime()==this.currentDate.getTime()){
			this.element.className=this.element.className+" current"
		}
		
		this.aElement.innerHTML=this.getText();
		this.aElement.appendChild(this.infoElement);
		
		this.element.appendChild(this.aElement);
		
		var self=this;
		$(this.element).bind("click",function(event){return self.clickHandle(event)})
	}
	Calendar.DayListItem.prototype.getText=function(){
		return this.num+1;
	}
	Calendar.DayListItem.prototype.getElement=function(){
		return this.element;
	}
	Calendar.DayListItem.prototype.clickHandle=function(event){
		this.focusControl(this.num);
		return true;
	}
	
	
	
	
	
	

	Calendar.ValueController=function(){
	}
	Calendar.ValueController.prototype.init=function(value){
		this.element=document.createElement("div");
		this.textElement=document.createElement("span");
		this.textElement.className="value"
		this.textElement.innerHTML=this.getText();
		
		this.nextButton=document.createElement("a")
		this.nextButton.className="nextButton"
		this.nextButton.innerHTML="&gt;"
		
		this.prevButton=document.createElement("a")
		this.prevButton.className="prevButton"
		this.prevButton.innerHTML="&lt;"

		
		this.element.appendChild(this.prevButton);
		this.element.appendChild(this.textElement);
		this.element.appendChild(this.nextButton);
		
		var self=this;
		
		$(this.prevButton).bind("click",function(event){self.prevButtonClickHandle(event)})
		$(this.nextButton).bind("click",function(event){self.nextButtonClickHandle(event)})
		
		
		this.update();
	}
	Calendar.ValueController.prototype.update=function(){
		this.textElement.innerHTML=this.getText();
	}
	Calendar.ValueController.prototype.setValue=function(value){
		this.value=value;
		this.update();
	}
	Calendar.ValueController.prototype.getText=function(){
		return this.value;
	}

	Calendar.ValueController.prototype.getElement=function(){
		return this.element;
	}
	Calendar.ValueController.prototype.prevButtonClickHandle=function(event){
		this.switchValue("-");
	}
	Calendar.ValueController.prototype.nextButtonClickHandle=function(event){
		this.switchValue("+");
	}









	Calendar.MonthController=function(value,switchValue){
		this.value=value;
		this.switchValue=switchValue;
		this.init();
	}
	Calendar.MonthController.prototype=new Calendar.ValueController();
	Calendar.MonthController.prototype.getText=function(){
		var text=Calendar.MONTH_DICT[this.value]
		return text;
	}
	Calendar.MonthController.prototype.getElement=function(){
		this.element=Calendar.ValueController.prototype.getElement.call(this);
		this.element.className="month"
		return this.element;
	}

	Calendar.YearController=function(value,switchValue){
		this.value=value;
		this.switchValue=switchValue;
		this.init();
	}
	Calendar.YearController.prototype=new Calendar.ValueController();
	Calendar.YearController.prototype.getElement=function(){
		this.element=Calendar.ValueController.prototype.getElement.call(this);
		this.element.className="year"
		return this.element;
	}
	Calendar.YearController.prototype.getText=function(){
		var text=this.value+"年"
		return text;
	}
	HTMLTurbo.control.Calendar=Calendar;
	// Page 页面基类
	var Page=function(selector,options){
	}
	Page.prototype.init=function(){
		htmlTurbo.init();
        window.reload=this.reload;
	}
	Page.prototype.update=function(){
	}
	Page.prototype.reload=function(){
	}
	HTMLTurbo.page.Page=Page;
	// ListPage 列表页面
	var ListPage=function(selector,options){
		this.selector=selector;
		this.options=options;
	}
	ListPage.prototype=new Page();
	ListPage.prototype.init=function(){
		this.clonePara();
        window.reload=this.reload;
	}
	
	ListPage.prototype.clonePara=function(){
		//var listParaList=$("#listForm").serializeArray();
		
		//搜索表单参数克隆到列表中
		var searchParaList=$("#searchForm").serializeArray();
		var html=this.paraListToParaTable(searchParaList);
		$("#listForm").prepend(html);
		
		//排序参数克隆到列表中
		var orderSerializeArray=this.getOrderSerializeArray();
		var html=this.paraListToParaTable(orderSerializeArray);
		$("#searchForm").prepend(html);
	}
	ListPage.prototype.getOrderSerializeArray=function(){
		var elementArray=$("#listForm thead input[type=hidden]")
		
		var serializeArray=Array();
		var serialize={};
		for(var i=0;i<elementArray.length;i++){
			var name=elementArray.get(i).name;
			var value=elementArray.get(i).value;

			serialize={}
			serialize.name=name;
			serialize.value=value;
			
			serializeArray.push(serialize);
		}
		return serializeArray;
	}
	ListPage.prototype.paraListToParaTable=function(paraList){
		var para=null;
		var html="<table class=\"ht-paraTable\">";
		var name="";
		var value="";
		for(var i=0;i<paraList.length;i++){
			para=paraList[i];
			name=para.name;
			value=para.value;
			
			html+="<tr><td><input type=\"text\" name=\"{name}\" value=\"{value}\" /></td></tr>";
			html=html.replace("{name}",name);
			html=html.replace("{value}",value);
		}
		html+="</table>";
		return html;
	}
	
	ListPage.prototype.reload=function(){
		$(".listForm").submit();
	}
	HTMLTurbo.page.ListPage=ListPage;
	// SelectorPage 选择页面
	var SelectorPage=function(selector,options){
		this.selector=selector;
		this.options=options;
	}
	SelectorPage.prototype=new ListPage();
	SelectorPage.prototype.init=function(){
		this.clonePara();
		var self=this;
		$(".table .select .button").bind("click",function(event){
			self.selectButtonClickHandler(event);
		})
        window.reload=this.reload;
	}
	SelectorPage.prototype.selectButtonClickHandler=function(event){
		var target=event.currentTarget;
		var item=$(target).parent().parent();
		this.select(item);
	}
	SelectorPage.prototype.select=function(item){
		console.log(item);
		/*var code=$("[name='value_code']",item).val();
		var name=$("[name='value_name']",item).val();
		console.log(code);
		
		
		var customer=new Customer();
		customer.setCode(code);
		customer.setName(name);
		
		console.log(customer);
		top.setCustomer(customer);
		top.ht.closeFocusFrameWindow();*/
	}
	HTMLTurbo.page.SelectorPage=SelectorPage;
	// FormPage 表单页面
	var FormPage=function(selector,options){
	}
	FormPage.prototype=new Page();
	FormPage.prototype.init=function(){
        window.reload=this.reload;
	}
	FormPage.prototype.reload=function(){
	}
	HTMLTurbo.page.FormPage=FormPage;
	// DetailPage 详细页面
	var DetailPage=function(selector,options){
	}
	DetailPage.prototype=new Page();
	DetailPage.prototype.init=function(){
        window.reload=this.reload;
	}
	DetailPage.prototype.reload=function(){
	}
	HTMLTurbo.page.DetailPage=DetailPage;

	window.HTMLTurbo=window.HT=HTMLTurbo;
}(window)

var htmlTurbo=new HTMLTurbo();
var ht=htmlTurbo;

//自定义控制台
ht.console=new HTMLTurbo.control.Console();
$(document.body).ready(
	function(){
		htmlTurbo.init();
	}
)
